Skip to content

Commit

Permalink
add targeted sample spec to demonstrate duplicated equivalent refs
Browse files Browse the repository at this point in the history
  • Loading branch information
ctreatma committed Dec 20, 2024
1 parent 153070c commit 0f9d0c5
Show file tree
Hide file tree
Showing 16 changed files with 466 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1958,6 +1958,21 @@ public void testRelativePath2() {
Assert.assertEquals(readResult.getOpenAPI().getPaths().get("/pet/findByTags").getGet().getResponses().get("default").getContent().get("application/json").getSchema().get$ref(), "#/components/schemas/ErrorModel");
}

@Test
public void testExternalRefsNormalization() throws Exception {
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = new OpenAPIV3Parser()
.readLocation("src/test/resources/oas3.fetched/openapi3.yaml", null, options);

OpenAPI openAPI = result.getOpenAPI();
Schema originalModel = openAPI.getComponents().getSchemas().get("Event");
Schema duplicateModel = openAPI.getComponents().getSchemas().get("Event_1");
System.out.println("component schemas found: " + openAPI.getComponents().getSchemas().keySet());
assertNull(duplicateModel);
assertNotNull(originalModel);
}

private OpenAPI doRelativeFileTest(String location) {
OpenAPIV3Parser parser = new OpenAPIV3Parser();
ParseOptions options = new ParseOptions();
Expand Down Expand Up @@ -3364,4 +3379,4 @@ public void testResolveFullyResponses(){
assertNull(openAPI.getPaths().get("/users").getGet().getResponses().get("400").get$ref());

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
description: Error responses are included with 4xx and 5xx HTTP responses from the
API service. Either "error" or "errors" will be set.
properties:
error:
description: A description of the error that caused the request to fail.
type: string
errors:
description: A list of errors that contributed to the request failing.
items:
description: An error message that contributed to the request failing.
type: string
type: array
type: object
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
properties:
body:
type: string
created_at:
format: date-time
type: string
href:
type: string
id:
format: uuid
type: string
interpolated:
type: string
relationships:
items:
$ref: './Href.yaml'
type: array
state:
type: string
type:
type: string
modified_by:
type: object
ip:
type: string
type: object
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
properties:
events:
items:
$ref: './Event.yaml'
type: array
meta:
$ref: './Meta.yaml'
type: object
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
properties:
href:
type: string
required:
- href
type: object
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
properties:
first:
$ref: './Href.yaml'
last:
$ref: './Href.yaml'
next:
$ref: './Href.yaml'
previous:
$ref: './Href.yaml'
self:
$ref: './Href.yaml'
total:
type: integer
current_page:
type: integer
last_page:
type: integer
type: object
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
openapi: 3.0.0
info:
version: 1.0.0
title: Example Duplicate Refs API
contact:
email: support@example.com
name: Example API Team
description: |
Sample API spec to validate handling of different file paths that reference the same file
license:
name: Equinix Metal
url: https://metal.equinix.com/legal/
termsOfService: https://metal.equinix.com/legal/
servers:
- url: https://api.example.com/duplicateRefs
components:
schemas:
Error:
$ref: "./components/schemas/Error.yaml"
Event:
$ref: "./components/schemas/Event.yaml"
EventList:
$ref: "./components/schemas/EventList.yaml"
paths:
/connections/{connection_id}/ports/{id}/events:
$ref: ./paths/connections/connection_id/ports/id/events.yaml
/devices/{id}/events:
$ref: ./paths/devices/id/events.yaml
/events:
$ref: ./paths/events.yaml
/events/{id}:
$ref: ./paths/events/id.yaml
/organizations/{id}/events:
$ref: ./paths/organizations/id/events.yaml
/projects/{id}/events:
$ref: ./paths/projects/id/events.yaml
/routes/{id}/events:
$ref: ./paths/routes/id/events.yaml
/virtual-circuits/{id}/events:
$ref: ./paths/virtual-circuits/id/events.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
get:
description: Returns a list of the interconnection events
operationId: findInterconnectionEvents
parameters:
- description: Interconnection UUID
in: path
name: connection_id
required: true
schema:
format: uuid
type: string
responses:
"200":
content:
application/json:
schema:
$ref: "../../../components/schemas/EventList.yaml"
description: ok
"401":
content:
application/json:
schema:
$ref: "../../../components/schemas/Error.yaml"
description: unauthorized
"403":
content:
application/json:
schema:
$ref: "../../../components/schemas/Error.yaml"
description: forbidden
"404":
content:
application/json:
schema:
$ref: "../../../components/schemas/Error.yaml"
description: not found
summary: Retrieve interconnection events
tags:
- Events
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
get:
description: Returns a list of the interconnection port events
operationId: findInterconnectionPortEvents
parameters:
- description: Interconnection UUID
in: path
name: connection_id
required: true
schema:
format: uuid
type: string
- description: Interconnection Port UUID
in: path
name: id
required: true
schema:
format: uuid
type: string
responses:
"200":
content:
application/json:
schema:
$ref: "../../../../../components/schemas/Event.yaml"
description: ok
"401":
content:
application/json:
schema:
$ref: "../../../../../components/schemas/Error.yaml"
description: unauthorized
"403":
content:
application/json:
schema:
$ref: "../../../../../components/schemas/Error.yaml"
description: forbidden
"404":
content:
application/json:
schema:
$ref: "../../../../../components/schemas/Error.yaml"
description: not found
summary: Retrieve interconnection port events
tags:
- Events
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
get:
description: Returns a list of events pertaining to a specific device
operationId: findDeviceEvents
parameters:
- description: Device UUID
in: path
name: id
required: true
schema:
format: uuid
type: string
responses:
"200":
content:
application/json:
schema:
$ref: "../../../components/schemas/EventList.yaml"
description: ok
"401":
content:
application/json:
schema:
$ref: "../../../components/schemas/Error.yaml"
description: unauthorized
"403":
content:
application/json:
schema:
$ref: "../../../components/schemas/Error.yaml"
description: forbidden
"404":
content:
application/json:
schema:
$ref: "../../../components/schemas/Error.yaml"
description: not found
summary: Retrieve device's events
tags:
- Events
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
get:
description: Returns a list of the current user’s events
operationId: findEvents
parameters:
responses:
"200":
content:
application/json:
schema:
$ref: "../components/schemas/EventList.yaml"
description: ok
"401":
content:
application/json:
schema:
$ref: "../components/schemas/Error.yaml"
description: unauthorized
summary: Retrieve current user's events
tags:
- Events
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
get:
description: Returns a single event if the user has access
operationId: findEventById
parameters:
- description: Event UUID
in: path
name: id
required: true
schema:
format: uuid
type: string
responses:
"200":
content:
application/json:
schema:
$ref: "../../components/schemas/Event.yaml"
description: ok
"401":
content:
application/json:
schema:
$ref: "../../components/schemas/Error.yaml"
description: unauthorized
"403":
content:
application/json:
schema:
$ref: "../../components/schemas/Error.yaml"
description: forbidden
"404":
content:
application/json:
schema:
$ref: "../../components/schemas/Error.yaml"
description: not found
summary: Retrieve an event
tags:
- Events
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
get:
description: Returns a list of events for a single organization
operationId: findOrganizationEvents
parameters:
- description: Organization UUID
in: path
name: id
required: true
schema:
format: uuid
type: string
responses:
"200":
content:
application/json:
schema:
$ref: "../../../components/schemas/EventList.yaml"
description: ok
"401":
content:
application/json:
schema:
$ref: "../../../components/schemas/Error.yaml"
description: unauthorized
"403":
content:
application/json:
schema:
$ref: "../../../components/schemas/Error.yaml"
description: forbidden
"404":
content:
application/json:
schema:
$ref: "../../../components/schemas/Error.yaml"
description: not found
summary: Retrieve organization's events
tags:
- Events
Loading

0 comments on commit 0f9d0c5

Please sign in to comment.