Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: duplication class name with ignore case. #72

Merged
merged 3 commits into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [10.x, 12.x, 14.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm run ci
21 changes: 12 additions & 9 deletions src/langs/php/combinator.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,16 @@ class Combinator extends CombinatorBase {
let tmp = realFullClassName.split('\\');
last = tmp[tmp.length - 1];
}

if (this.classNameMap[last]) {
if (this.classNameMap[last] !== realFullClassName) {
let lower = last.toLowerCase();
if (this.classNameMap[lower]) {
if (this.classNameMap[lower] !== realFullClassName) {
// return full class name if already have same name class
return realFullClassName;
}
return last;
}

this.classNameMap[last] = realFullClassName;
this.classNameMap[lower] = realFullClassName;
if (this.thirdPackageClientAlias[className]) {
// has alias
this.includeList.push({ import: realFullClassName, alias: this.thirdPackageClientAlias[className] });
Expand Down Expand Up @@ -145,14 +145,15 @@ class Combinator extends CombinatorBase {

let tmp = realFullClassName.split('\\');
let last = tmp[tmp.length - 1];
if (this.classNameMap[last]) {
if (this.classNameMap[last] !== realFullClassName) {
let lower = last.toLowerCase();
if (this.classNameMap[lower]) {
if (this.classNameMap[lower] !== realFullClassName) {
// return full class name if already have same name class
return realFullClassName;
}
return last;
}
this.classNameMap[last] = realFullClassName;
this.classNameMap[lower] = realFullClassName;
this.includeModelList.push({ import: realFullClassName, alias: null });
return last;
}
Expand Down Expand Up @@ -327,13 +328,15 @@ class Combinator extends CombinatorBase {
className = this.config.client.name;
this.config.filename = className;
}
className = _avoidKeywords(className);
if (object.annotations.length > 0) {
this.emitAnnotations(emitter, object.annotations);
}
if (_isKeywords(className)) {
this.config.filename = _avoidKeywords(className);
this.config.filename = className;
}
emitter.emitln(`class ${_avoidKeywords(className)} ${parent}{`, this.level);
this.classNameMap[className.toLowerCase()] = className;
emitter.emitln(`class ${className} ${parent}{`, this.level);
this.levelUp();
const notes = this.resolveNotes(object.body);
if (Object.keys(notes).length > 0) {
Expand Down
12 changes: 12 additions & 0 deletions tests/expected/complex/Models/ComplexRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ComplexRequest extends Model {
'part' => 'Part',
];
public function validate() {
Model::validateRequired('duplicatName', $this->duplicatName, true);
Model::validateRequired('accessKey', $this->accessKey, true);
Model::validateRequired('body', $this->body, true);
Model::validateRequired('strs', $this->strs, true);
Expand All @@ -27,6 +28,9 @@ public function validate() {
}
public function toMap() {
$res = [];
if (null !== $this->duplicatName) {
$res['duplicatName'] = null !== $this->duplicatName ? $this->duplicatName->toMap() : null;
}
if (null !== $this->accessKey) {
$res['accessKey'] = $this->accessKey;
}
Expand Down Expand Up @@ -62,6 +66,9 @@ public function toMap() {
*/
public static function fromMap($map = []) {
$model = new self();
if(isset($map['duplicatName'])){
$model->duplicatName = \Source\Models\complexrequest::fromMap($map['duplicatName']);
}
if(isset($map['accessKey'])){
$model->accessKey = $map['accessKey'];
}
Expand Down Expand Up @@ -93,6 +100,11 @@ public static function fromMap($map = []) {
}
return $model;
}
/**
* @var \Source\Models\complexrequest
*/
public $duplicatName;

/**
* @var string
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/expected/model/Models/Class_.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function toMap() {
}
/**
* @param array $map
* @return Class
* @return Class_
*/
public static function fromMap($map = []) {
$model = new self();
Expand Down
4 changes: 4 additions & 0 deletions tests/fixtures/complex/libraries/import.dara
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ model Request = {
extra: map[string] string
},
}

model complexrequest = {

}
1 change: 1 addition & 0 deletions tests/fixtures/complex/main.dara
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ init(config: Source.Config){
}

model ComplexRequest = {
duplicatName: Source.complexrequest,
accessKey: string,
body: readable(name='Body', example='Body', description='Body'),
strs: [ string ](name='Strs', example='Strs', description='Strs'),
Expand Down