[General] generator fails with oas 3 that includes remote ref that includes (remote's) local file ref
Description
Generator fails when it reads openapi.yaml that includes remote ref file ref that includes (remote's) local file ref (i.e. root -> remote ref -> (remote's) local ref).
This problem was found while confirming https://github.com/OpenAPITools/openapi-generator/issues/851 is fixed.
I use "jaxrs-jersey" language for this sample, but I think the problem is not limtied in jaxrs-jersey or java. All languages are affected, because the parser might be the root problem.
openapi-generator version
current master (abe741f9891d74aeb05260e6221c5bc9f870af5c)
OpenAPI declaration file content or url
https://gist.github.com/fujigon/e2e1594a011022245e66fa6c21954ea9
Command line used for generation
# git clone, etc
mvn package
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i openapi.yaml -g jaxrs-jersey
Steps to reproduce
When I execute the generator with the gisted openapi.yaml file, I get
$ java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i openapi.yaml -g jaxrs-jersey -o generated-code
[main] INFO o.o.codegen.DefaultCodegen - Skipped overwriting pom.xml as the file already exists in C:\publicgithub\openapi-generator\generated-code\\pom.xml
[main] INFO o.o.codegen.DefaultCodegen - Skipped overwriting README.md as the file already exists in C:\publicgithub\openapi-generator\generated-code\\README.md
[main] INFO o.o.codegen.DefaultCodegen - Skipped overwriting Bootstrap.java as the file already exists in C:\publicgithub\openapi-generator\generated-code\src/main/java/org/openapitools/api\Bootstrap.java
[main] INFO o.o.codegen.DefaultCodegen - Skipped overwriting web.xml as the file already exists in C:\publicgithub\openapi-generator\generated-code\src/main/webapp/WEB-INF\web.xml
[main] ERROR o.o.codegen.DefaultCodegen - No Type defined for Additional Property class Schema {
title: null
multipleOf: null
maximum: null
exclusiveMaximum: null
minimum: null
exclusiveMinimum: null
maxLength: null
minLength: null
pattern: null
maxItems: null
minItems: null
uniqueItems: null
maxProperties: null
minProperties: null
required: null
type: null
not: null
properties: null
additionalProperties: null
description: null
format: null
$ref: #/components/schemas/rel-data
nullable: null
readOnly: null
writeOnly: null
example: null
externalDocs: null
deprecated: null
discriminator: null
xml: null
}
In Property: class ObjectSchema {
class Schema {
title: null
multipleOf: null
maximum: null
exclusiveMaximum: null
minimum: null
exclusiveMinimum: null
maxLength: null
minLength: null
pattern: null
maxItems: null
minItems: null
uniqueItems: null
maxProperties: null
minProperties: null
required: null
type: null
not: null
properties: null
additionalProperties: class Schema {
title: null
multipleOf: null
maximum: null
exclusiveMaximum: null
minimum: null
exclusiveMinimum: null
maxLength: null
minLength: null
pattern: null
maxItems: null
minItems: null
uniqueItems: null
maxProperties: null
minProperties: null
required: null
type: null
not: null
properties: null
additionalProperties: null
description: null
format: null
$ref: #/components/schemas/rel-data
nullable: null
readOnly: null
writeOnly: null
example: null
externalDocs: null
deprecated: null
discriminator: null
xml: null
}
description: null
format: null
$ref: null
nullable: null
readOnly: null
writeOnly: null
example: null
externalDocs: null
deprecated: null
discriminator: null
xml: null
}
type: object
defaultObject: null
}
[main] ERROR o.o.codegen.DefaultCodegen - No Type defined for Additional Property class Schema {
title: null
multipleOf: null
maximum: null
exclusiveMaximum: null
minimum: null
exclusiveMinimum: null
maxLength: null
minLength: null
pattern: null
maxItems: null
minItems: null
uniqueItems: null
maxProperties: null
minProperties: null
required: null
type: null
not: null
properties: null
additionalProperties: null
description: null
format: null
$ref: #/components/schemas/rel-data
nullable: null
readOnly: null
writeOnly: null
example: null
externalDocs: null
deprecated: null
discriminator: null
xml: null
}
In Property: class ObjectSchema {
class Schema {
title: null
multipleOf: null
maximum: null
exclusiveMaximum: null
minimum: null
exclusiveMinimum: null
maxLength: null
minLength: null
pattern: null
maxItems: null
minItems: null
uniqueItems: null
maxProperties: null
minProperties: null
required: null
type: null
not: null
properties: null
additionalProperties: class Schema {
title: null
multipleOf: null
maximum: null
exclusiveMaximum: null
minimum: null
exclusiveMinimum: null
maxLength: null
minLength: null
pattern: null
maxItems: null
minItems: null
uniqueItems: null
maxProperties: null
minProperties: null
required: null
type: null
not: null
properties: null
additionalProperties: null
description: null
format: null
$ref: #/components/schemas/rel-data
nullable: null
readOnly: null
writeOnly: null
example: null
externalDocs: null
deprecated: null
discriminator: null
xml: null
}
description: null
format: null
$ref: null
nullable: null
readOnly: null
writeOnly: null
example: null
externalDocs: null
deprecated: null
discriminator: null
xml: null
}
type: object
defaultObject: null
}
[main] INFO o.o.codegen.AbstractGenerator - writing file C:\publicgithub\openapi-generator\generated-code\src\gen\java\org\openapitools\model\LinkObject.java
[main] INFO o.o.codegen.AbstractGenerator - writing file C:\publicgithub\openapi-generator\generated-code\src\gen\java\org\openapitools\model\RelData.java
[main] INFO o.o.codegen.AbstractGenerator - writing file C:\publicgithub\openapi-generator\generated-code\src\gen\java\org\openapitools\model\SchemaIncludingExternalRef.java
[main] WARN o.o.codegen.DefaultCodegen - Empty operationId found for path: get /tests/refToSchemaIncludingExternalRef/fromRef1. Renamed to auto-generated operationId: testsRefToSchemaIncludingExternalRefFromRef1Get
[main] INFO o.o.codegen.AbstractGenerator - writing file C:\publicgithub\openapi-generator\generated-code\src\main\java\org\openapitools\api\impl\TestsApiServiceImpl.java
[main] INFO o.o.codegen.AbstractGenerator - writing file C:\publicgithub\openapi-generator\generated-code\src\gen\java\org\openapitools\api\TestsApi.java
[main] INFO o.o.codegen.AbstractGenerator - writing file C:\publicgithub\openapi-generator\generated-code\src\gen\java\org\openapitools\api\TestsApiService.java
[main] INFO o.o.codegen.AbstractGenerator - writing file C:\publicgithub\openapi-generator\generated-code\src\main\java\org\openapitools\api\factories\TestsApiServiceFactory.java
[main] INFO o.o.codegen.AbstractGenerator - writing file C:\publicgithub\openapi-generator\generated-code\src/gen/java/org/openapitools/api\ApiException.java
[main] INFO o.o.codegen.AbstractGenerator - writing file C:\publicgithub\openapi-generator\generated-code\src/gen/java/org/openapitools/api\ApiOriginFilter.java
[main] INFO o.o.codegen.AbstractGenerator - writing file C:\publicgithub\openapi-generator\generated-code\src/gen/java/org/openapitools/api\ApiResponseMessage.java
[main] INFO o.o.codegen.AbstractGenerator - writing file C:\publicgithub\openapi-generator\generated-code\src/gen/java/org/openapitools/api\NotFoundException.java
[main] INFO o.o.codegen.AbstractGenerator - writing file C:\publicgithub\openapi-generator\generated-code\src/gen/java/org/openapitools/api\JacksonJsonProvider.java
[main] INFO o.o.codegen.AbstractGenerator - writing file C:\publicgithub\openapi-generator\generated-code\src/gen/java/org/openapitools/api\RFC3339DateFormat.java
[main] INFO o.o.codegen.AbstractGenerator - writing file C:\publicgithub\openapi-generator\generated-code\src/gen/java/org/openapitools/api\StringUtil.java
[main] INFO o.o.codegen.AbstractGenerator - writing file C:\publicgithub\openapi-generator\generated-code\.openapi-generator\VERSION
Related issues/PRs
Suggest a fix/enhancement
The remote ref (https://raw.githubusercontent.com/swagger-api/swagger-parser/v2.0.2/modules/swagger-parser-v3/src/test/resources/relative/globals.yaml#/components/schemas/link-object)
has its local ref
link-object:
type: object
additionalProperties:
"$ref": "#/components/schemas/rel-data"
I confirmed that when I set the remote ref to https://raw.githubusercontent.com/swagger-api/swagger-parser/v2.0.2/modules/swagger-parser-v3/src/test/resources/relative/globals.yaml#/components/schemas/rel-data, which doens't include local ref, the generator successfully runs.
Probably, the swagger-parser doens't recognize "remote -> its local" pattern ref...
I'll investigate and debug the parser, and report here when I find any information.
confirmed that this issue is fixed with current master 4e8844273be501a879321b317da9f12c83f23b2b , probably because of updating swagger-parser to 2.0.4 https://github.com/OpenAPITools/openapi-generator/pull/787
@jmini @wing328 thanks for fixing. confirmed it works. I closed the issue.