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: "isAlias" of CodegenModel #2758

Merged
merged 8 commits into from
Feb 19, 2020
Merged

Conversation

ackintosh
Copy link
Contributor

@ackintosh ackintosh commented Apr 29, 2019

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\.
  • Filed the PR against the correct branch: master, 3.4.x, 4.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

components:
  schemas:
    MyParameterTextField:
      $ref: '#/components/schemas/AliasToString'
    AliasToString:
      type: string
      minLength: 1
      maxLength: 50

A CodegenModel instance built from the MyParameterTextField definition should be alias. (the instance should have a property isAlias = true.)

);

Assert.assertTrue(model.isAlias);
Assert.assertEquals("string", model.dataType);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In some of generators (e.g. Kotlin which supports Type Alias), it may expected that the dataType property has a specific model type for better type alias support.

ref #2574

@ackintosh
Copy link
Contributor Author

cc @OpenAPITools/generator-core-team

@wing328 wing328 added this to the 4.0.0 milestone May 2, 2019
@wing328
Copy link
Member

wing328 commented May 6, 2019

Looks like the fix breaks the haskell client generator:

➜  graphql-generator git:(ackintosh-is-alias) ./bin/haskell-http-client-petstore.sh
# START SCRIPT: ./bin/haskell-http-client-petstore.sh
java  -Xmx1024M -DloggerPath=conf/log4j.properties -jar ./modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -t modules/openapi-generator/src/main/resources/haskell-http-client -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g haskell-http-client -o samples/client/petstore/haskell-http-client
[main] INFO  o.o.codegen.DefaultGenerator - OpenAPI Generator: haskell-http-client (client)
[main] INFO  o.o.codegen.DefaultGenerator - Generator 'haskell-http-client' is considered stable.
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one
[main] INFO  o.o.c.l.HaskellHttpClientCodegen - Hint: Environment variable HASKELL_POST_PROCESS_FILE not defined so the Haskell code may not be properly formatted. To define it, try 'export HASKELL_POST_PROCESS_FILE="$HOME/.local/bin/hfmt -w"' (Linux/Mac)
Exception in thread "main" java.lang.RuntimeException: Could not process model 'Dog'.Please make sure that your schema is correct!
	at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:470)
	at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:919)
	at org.openapitools.codegen.cmd.Generate.run(Generate.java:396)
	at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:60)
Caused by: java.lang.NullPointerException
	at org.openapitools.codegen.languages.HaskellHttpClientCodegen.postProcessModels(HaskellHttpClientCodegen.java:1234)
	at org.openapitools.codegen.DefaultGenerator.processModels(DefaultGenerator.java:1195)
	at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:465)
	... 3 more

@wing328 wing328 modified the milestones: 4.0.0, 4.0.1 May 13, 2019
@wing328 wing328 modified the milestones: 4.0.1, 4.0.2 May 31, 2019
@wing328 wing328 modified the milestones: 4.0.2, 4.0.3 Jun 20, 2019
@wing328 wing328 modified the milestones: 4.0.3, 4.1.0 Jul 9, 2019
@wing328 wing328 modified the milestones: 4.1.0, 4.1.1 Aug 9, 2019
@wing328 wing328 modified the milestones: 4.1.1, 4.1.2 Aug 26, 2019
@wing328 wing328 modified the milestones: 4.1.2, 4.1.3 Sep 11, 2019
@wing328 wing328 modified the milestones: 4.1.3, 4.2.0 Oct 4, 2019
@wing328 wing328 removed this from the 4.2.0 milestone Oct 30, 2019
@hosswald
Copy link

@ackintosh @wing328 I realized that #2574 is still open... I would appreciate if this would find its way into a release soon. Thanks.

@ackintosh
Copy link
Contributor Author

Thanks for pinging me. I'll restart working on this issue later this week. 😃

@ackintosh
Copy link
Contributor Author

I've fixed the error in haskel client generator. @wing328 Please have a look when you have time.

@wing328
Copy link
Member

wing328 commented Feb 18, 2020

cc @OpenAPITools/generator-core-team as well.

@wing328
Copy link
Member

wing328 commented Feb 19, 2020

Looks good to me but I didn't test it locally.

@wing328 wing328 merged commit 37556c2 into OpenAPITools:master Feb 19, 2020
@wing328 wing328 added this to the 4.3.0 milestone Feb 19, 2020
MikailBag pushed a commit to MikailBag/openapi-generator that referenced this pull request Mar 23, 2020
* Add test case to reproduce the issue

OpenAPITools#2574

* Fix: an alias of "an alias of simple OAS type" has an incorrect property `isAlias: false`

* Use ModelUtils instead of referring the "type" value directly

* Delete an unnecessary condition

* Tweak: the order of conditions

* Fix wrong "isAlias" value on ComposedSchema
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants