Skip to content

Commit 1b97b41

Browse files
hertzsprungJames Shaw
authored andcommitted
set resolveResponses=true
needed by swagger-parser>=2.1.23, see swagger-api/swagger-parser#2127
1 parent 64ab13a commit 1b97b41

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/config/CodegenConfigurator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,7 @@ public Context<?> toContext() {
683683
final List<AuthorizationValue> authorizationValues = AuthParser.parse(this.auth);
684684
ParseOptions options = new ParseOptions();
685685
options.setResolve(true);
686+
options.setResolveResponses(true);
686687
SwaggerParseResult result = new OpenAPIParser().readLocation(inputSpec, authorizationValues, options);
687688

688689
// TODO: Move custom validations to a separate type as part of a "Workflow"

modules/openapi-generator/src/test/java/org/openapitools/codegen/config/CodegenConfiguratorTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.openapitools.codegen.config;
1818

19+
import io.swagger.v3.oas.models.OpenAPI;
20+
import org.junit.jupiter.api.Assertions;
1921
import org.openapitools.codegen.ClientOptInput;
2022
import org.openapitools.codegen.CodegenConfig;
2123
import org.openapitools.codegen.CodegenConstants;
@@ -121,4 +123,14 @@ public void shouldSetConfigProperties() throws IOException {
121123
want(props, "foo", "bar");
122124
want(props, "baz", "quux");
123125
}
126+
127+
@Test
128+
public void resolvesResponses() {
129+
@SuppressWarnings("unchecked") Context<OpenAPI> context = (Context<OpenAPI>) new CodegenConfigurator()
130+
.setInputSpec("src/test/resources/3_0/response-ref.yaml")
131+
.setGeneratorName("java")
132+
.toContext();
133+
134+
Assertions.assertNotNull(context.getSpecDocument().getPaths().get("/hello").getGet().getResponses().get("200").getContent());
135+
}
124136
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
openapi: 3.0.1
2+
info:
3+
title: ping test
4+
version: '1.0'
5+
servers:
6+
- url: 'http://localhost:8000/'
7+
paths:
8+
/hello:
9+
get:
10+
operationId: hello
11+
responses:
12+
'200':
13+
$ref: "#/components/responses/refResponse"
14+
15+
components:
16+
responses:
17+
refResponse:
18+
description: a response specification `$ref`erenced from an operation
19+
content:
20+
application/json:
21+
schema:
22+
type: object
23+
properties:
24+
responseProperty:
25+
type: string

0 commit comments

Comments
 (0)