Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some code I added to make OpenApi reader work on my files #26

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
@@ -0,0 +1,179 @@
as yet unclassified
petStoreApiJsonStringWithEnum
^ '{
"openapi": "3.0.0",
"info": {
"version": "1.0.0",
"title": "Swagger Petstore",
"license": {
"name": "MIT"
}
},
"servers": [
{
"url": "http://petstore.swagger.io/v1"
}
],
"paths": {
"/pets": {
"get": {
"summary": "List all pets",
"operationId": "listPets",
"tags": [
"pets"
],
"parameters": [
{
"name": "limit",
"in": "query",
"description": "How many items to return at one time (max 100)",
"required": false,
"schema": {
"type": "integer",
"format": "int32"
}
}
],
"responses": {
"200": {
"description": "An paged array of pets",
"headers": {
"x-next": {
"description": "A link to the next page of responses",
"schema": {
"type": "string"
}
}
},
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Pets"
}
}
}
},
"default": {
"description": "unexpected error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
}
}
},
"post": {
"summary": "Create a pet",
"operationId": "createPets",
"tags": [
"pets"
],
"requestBody" : {

"content": {
"application/json": {
"schema": {
"type": "array",
"items": {"$ref": "#/components/schemas/Pet"},
"minItems": 1
}
}
}
},
"responses": {
"201": {
"description": "Null response"
},
"default": {
"description": "unexpected error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
}
}
}
},
"/pets/{petId}": {
"get": {
"summary": "Info for a specific pet",
"operationId": "showPetById",
"tags": [
"pets"
],
"parameters": [
{
"name": "petId",
"in": "path",
"required": true,
"description": "The id of the pet to retrieve",
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "Expected response to a valid request",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Pets"
}
}
}
},
"default": {
"description": "unexpected error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"Pet": {
"type": "string",
"enum": [
"PET_A",
"PET_B"
]
},
"Pets": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Pet"
}
},
"Error": {
"type" : "object",
"required": [
"code",
"message"
],
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"message": {
"type": "string"
}
}
}
}
}
}'
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
as yet unclassified
responseObjectJSONWithLinks
^ '
{
"description": "Response with links",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"_embedded"
],
"properties": {
"_embedded": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Booking"
}
}
}
}
}
},
"links": {
"getActionsForBooking": {
"$ref": "#/components/links/getActionsForBooking"
}
}
}

'.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
as yet unclassified
schemaArrayMinItems

^ '{

"type": "array",
"items": {"$ref": "#/components/schemas/Pet"},
"minItems": 1

}'
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
tests
testParsingOpenAPIWithEnum
| api path |
api := OpenAPI fromString: self petStoreApiJsonStringWithEnum.
self assert: api info title equals: 'Swagger Petstore'.
self assert: api openapi equals: '3.0.0'.
self assert: api paths size = 2.

path := api paths values first.
path should beInstanceOf: OAPathItem.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
tests
testParsingResponseWithLinks
| response |
response := NeoJSONReader fromString: self responseObjectJSONWithLinks as: OAResponse.

response should beInstanceOf: OAResponse.
response description should equal: 'Response with links'.

response content should
beInstanceOf: Dictionary;
haveSize: 1;
includeKey: 'application/json'.
response content values do: [ :each | each should beInstanceOf: OAMediaTypeObject. ].
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
tests
testParsingSchemaMinItems
| schemaDefinition |
schemaDefinition := NeoJSONReader fromString: self schemaArrayMinItems as: OASchemaDefinition.
self assert: schemaDefinition schemaClass equals: JSONSchemaArray