Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@ public Context<?> toContext() {
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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -121,4 +123,14 @@ public void shouldSetConfigProperties() throws IOException {
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());
}
}
25 changes: 25 additions & 0 deletions modules/openapi-generator/src/test/resources/3_0/response-ref.yaml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion samples/server/petstore/go-api-server/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion samples/server/petstore/go-chi-server/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading