mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-10-14 00:13:50 +00:00
Fix response model generation with ParseOptions.resolveResponses=true (#21568)
* set resolveResponses=true needed by swagger-parser>=2.1.23, see https://github.com/swagger-api/swagger-parser/pull/2127 * update samples --------- Co-authored-by: James Shaw <james.shaw@masabi.com>
This commit is contained in:
parent
f632ab7977
commit
7ca3fc3115
@ -683,6 +683,7 @@ public class CodegenConfigurator {
|
||||
final List<AuthorizationValue> authorizationValues = AuthParser.parse(this.auth);
|
||||
ParseOptions options = new ParseOptions();
|
||||
options.setResolve(true);
|
||||
options.setResolveResponses(true);
|
||||
SwaggerParseResult result = new OpenAPIParser().readLocation(inputSpec, authorizationValues, options);
|
||||
|
||||
// TODO: Move custom validations to a separate type as part of a "Workflow"
|
||||
|
@ -16,6 +16,8 @@
|
||||
|
||||
package org.openapitools.codegen.config;
|
||||
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.openapitools.codegen.ClientOptInput;
|
||||
import org.openapitools.codegen.CodegenConfig;
|
||||
import org.openapitools.codegen.CodegenConstants;
|
||||
@ -121,4 +123,14 @@ public class CodegenConfiguratorTest {
|
||||
want(props, "foo", "bar");
|
||||
want(props, "baz", "quux");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolvesResponses() {
|
||||
@SuppressWarnings("unchecked") Context<OpenAPI> context = (Context<OpenAPI>) new CodegenConfigurator()
|
||||
.setInputSpec("src/test/resources/3_0/response-ref.yaml")
|
||||
.setGeneratorName("java")
|
||||
.toContext();
|
||||
|
||||
Assertions.assertNotNull(context.getSpecDocument().getPaths().get("/hello").getGet().getResponses().get("200").getContent());
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
openapi: 3.0.1
|
||||
info:
|
||||
title: ping test
|
||||
version: '1.0'
|
||||
servers:
|
||||
- url: 'http://localhost:8000/'
|
||||
paths:
|
||||
/hello:
|
||||
get:
|
||||
operationId: hello
|
||||
responses:
|
||||
'200':
|
||||
$ref: "#/components/responses/refResponse"
|
||||
|
||||
components:
|
||||
responses:
|
||||
refResponse:
|
||||
description: a response specification `$ref`erenced from an operation
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
responseProperty:
|
||||
type: string
|
@ -15,7 +15,13 @@ paths:
|
||||
operationId: getAllFoos
|
||||
responses:
|
||||
"200":
|
||||
$ref: "#/components/responses/200FooArray"
|
||||
content:
|
||||
application/json;charset=utf-8:
|
||||
schema:
|
||||
items:
|
||||
$ref: "#/components/schemas/FooRefOrValue"
|
||||
type: array
|
||||
description: Success
|
||||
summary: GET all Foos
|
||||
tags:
|
||||
- Foo
|
||||
@ -29,7 +35,11 @@ paths:
|
||||
$ref: "#/components/requestBodies/Foo"
|
||||
responses:
|
||||
"201":
|
||||
$ref: "#/components/responses/201Foo"
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/FooRefOrValue"
|
||||
description: Error
|
||||
summary: Create a Foo
|
||||
tags:
|
||||
- Foo
|
||||
|
@ -15,7 +15,13 @@ paths:
|
||||
operationId: getAllFoos
|
||||
responses:
|
||||
"200":
|
||||
$ref: "#/components/responses/200FooArray"
|
||||
content:
|
||||
application/json;charset=utf-8:
|
||||
schema:
|
||||
items:
|
||||
$ref: "#/components/schemas/FooRefOrValue"
|
||||
type: array
|
||||
description: Success
|
||||
summary: GET all Foos
|
||||
tags:
|
||||
- Foo
|
||||
@ -29,7 +35,11 @@ paths:
|
||||
$ref: "#/components/requestBodies/Foo"
|
||||
responses:
|
||||
"201":
|
||||
$ref: "#/components/responses/201Foo"
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/FooRefOrValue"
|
||||
description: Error
|
||||
summary: Create a Foo
|
||||
tags:
|
||||
- Foo
|
||||
|
@ -918,7 +918,11 @@ paths:
|
||||
$ref: "#/components/requestBodies/TestBody"
|
||||
responses:
|
||||
"200":
|
||||
$ref: "#/components/responses/SuccessfulOp"
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: bool
|
||||
description: Successful Operation
|
||||
summary: POST a test batch
|
||||
tags:
|
||||
- fake
|
||||
|
@ -918,7 +918,11 @@ paths:
|
||||
$ref: "#/components/requestBodies/TestBody"
|
||||
responses:
|
||||
"200":
|
||||
$ref: "#/components/responses/SuccessfulOp"
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: bool
|
||||
description: Successful Operation
|
||||
summary: POST a test batch
|
||||
tags:
|
||||
- fake
|
||||
|
Loading…
x
Reference in New Issue
Block a user