Skip to content

Commit

Permalink
Merge pull request swagger-api#1609 from swagger-api/issue-1561
Browse files Browse the repository at this point in the history
Fix and Issue 1561: Add resolved responses to components section in main spec
  • Loading branch information
gracekarina committed Sep 23, 2021
2 parents 99d79ea + 2d1c96f commit e8ff89b
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 3 deletions.
Expand Up @@ -391,6 +391,7 @@ public String processRefToExternalResponse(String $ref, RefFormat refFormat) {
}
}
newRef = possiblyConflictingDefinitionName;
openAPI.getComponents().addResponses(newRef, response);
cache.putRenamedRef($ref, newRef);

if(response != null) {
Expand All @@ -408,6 +409,7 @@ public String processRefToExternalResponse(String $ref, RefFormat refFormat) {
return newRef;
}


public String processRefToExternalRequestBody(String $ref, RefFormat refFormat) {
String renamedRef = cache.getRenamedRef($ref);
if(renamedRef != null) {
Expand Down
Expand Up @@ -51,6 +51,7 @@ public void processOperation(Operation operation) {
for (String responseCode : responses.keySet()) {
ApiResponse response = responses.get(responseCode);
if(response != null) {
//This part allows parser to put response schema inline without the resolveFully option set to true
if (response.get$ref() != null) {

responseProcessor.processResponse(response);
Expand All @@ -63,9 +64,7 @@ public void processOperation(Operation operation) {
responses.put(responseCode, resolvedResponse);
}
}

responseProcessor.processResponse(response);

}
}
}
Expand Down
Expand Up @@ -81,7 +81,11 @@ public void processReferenceResponse(ApiResponse response){
RefFormat refFormat = computeRefFormat(response.get$ref());
String $ref = response.get$ref();
if (isAnExternalRefFormat(refFormat)){
externalRefProcessor.processRefToExternalResponse($ref, refFormat);
final String newRef = externalRefProcessor.processRefToExternalResponse($ref, refFormat);

if (newRef != null) {
response.set$ref(newRef);
}
}
}
}
Expand Up @@ -83,6 +83,15 @@ public class OpenAPIV3ParserTest {
protected int serverPort = getDynamicPort();
protected WireMockServer wireMockServer;

@Test
public void testIssue1561() {
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = new OpenAPIV3Parser().readLocation("issue-1561/swagger.yaml", null, options);
OpenAPI openAPI = result.getOpenAPI();
assertTrue(openAPI.getComponents().getResponses().size() == 3);
}

@Test
public void testAnonymousModelAllOf() {
ParseOptions options = new ParseOptions();
Expand Down
@@ -0,0 +1,67 @@
components:
schemas:
Exception:
type: object
Rfc7807Exception:
description: The Rfc7807 specification for exceptions.
allOf:
- $ref: '#/components/schemas/Exception'
- type: object
properties:
type:
type: string
description: A URI reference that identifies the problem type.
required:
- type
- title
- status
- detail
AbsisExceptionType:
type: string
enum: [VALIDATION, BUSINESS, RUNTIME, CHALLENGE, NOTFOUND, UNAUTHORIZED, AUTHENTICATION]
description: The possible types of an AbsisException.
AbsisFieldError:
type: object
description: The representation of a validation error.
properties:
code:
type: string
description: The error code.
example:
code: request
parameters:
- codes:
- aCode
- otherCode
value: NotNull
AbsisException:
description: Representation of an exception.
allOf:
- $ref: '#/components/schemas/Rfc7807Exception'
- type: object
properties:
_class:
type: string
description: The canonical name of the class AbsisException.
cause:
$ref: '#/components/schemas/AbsisException'
description: The AbsisException wrapping the exception that originated this exception.
responses:
'400':
description: Error when validating input parameters or request body.
content:
application/json:
schema:
$ref: '#/components/schemas/AbsisException'
'404':
description: The endpoint does not exists or the attempted resource does not exist.
content:
application/json:
schema:
$ref: '#/components/schemas/AbsisException'
'500':
description: Unexpected error occurred at one of the layers of the microservice, controller, business service, repository etc.
content:
application/json:
schema:
$ref: '#/components/schemas/AbsisException'
@@ -0,0 +1,67 @@
openapi: 3.0.0
info:
description: The Trazabilidad API offers the functionalities of the new trace regardless of the channel in which it is in invoked.
version: 1.0.2
title: ApiTrazabilidad

tags:
- name: Trazabilidad
description: Trazabilidad API
paths:
'/operationalServices/tracks/scopes/{scopeId}/processes/{processId}/petitions':
post:
tags:
- createPetition
summary: Creates a new instance in the traceability operation.
operationId: createPetition
description: Creates a new instance in the traceability operation.
parameters:
- in: path
name: processId
description: instance process ID
required: true
schema:
type: integer
requestBody:
$ref: '#/components/requestBodies/TrazabilidadBodyRequest'
responses:
'201':
description: Created
content:
application/json:
schema:
$ref: '#/components/schemas/BodyOutResponse'
'400':
$ref: >-
exceptions.yml#/components/responses/400
'404':
$ref: >-
exceptions.yml#/components/responses/404
'500':
$ref: >-
exceptions.yml#/components/responses/500
components:
requestBodies:
TrazabilidadBodyRequest:
content:
application/json:
schema:
$ref: '#/components/schemas/TrazabilidadBodyRequest'
description: body request
required: true
schemas:
BodyOutResponse:
type: object
properties:
petitionId:
type: string
description: The ID of the request that has been created
example: "971205125921"
TrazabilidadBodyRequest:
type: object
properties:
action:
type: string
description: Action to be performed. values -- alta , mod , fin , baja
example: "alta"

0 comments on commit e8ff89b

Please sign in to comment.