Merge pull request #2490 from wing328/fix_spec_typo

[Sinatra] fix typo, update sinatra to use origianl petstore spec (yaml)
This commit is contained in:
wing328 2016-04-04 16:29:13 +08:00
commit af75243a31
8 changed files with 600 additions and 857 deletions

View File

@ -26,6 +26,6 @@ fi
# if you've executed sbt assembly previously it will use that instead. # if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="$@ generate -t modules/swagger-codegen/src/main/resources/sinatra -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l sinatra -o samples/server/petstore/sinatra" ags="$@ generate -t modules/swagger-codegen/src/main/resources/sinatra -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l sinatra -o samples/server/petstore/sinatra"
java $JAVA_OPTS -jar $executable $ags java $JAVA_OPTS -jar $executable $ags

View File

@ -1301,7 +1301,7 @@
} }
}, },
"Return": { "Return": {
"descripton": "Model for testing reserved words", "description": "Model for testing reserved words",
"properties": { "properties": {
"return": { "return": {
"type": "integer", "type": "integer",
@ -1313,7 +1313,7 @@
} }
}, },
"Name": { "Name": {
"descripton": "Model for testing model name same as property name", "description": "Model for testing model name same as property name",
"properties": { "properties": {
"name": { "name": {
"type": "integer", "type": "integer",
@ -1329,7 +1329,7 @@
} }
}, },
"200_response": { "200_response": {
"descripton": "Model for testing model name starting with number", "description": "Model for testing model name starting with number",
"properties": { "properties": {
"name": { "name": {
"type": "integer", "type": "integer",

View File

@ -1,386 +1,308 @@
swagger: '2.0' swagger: "2.0"
info: info:
description: | description: |
This is a sample server Petstore server. You can find out more about This is a sample server Petstore server.
Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/).
For this sample, you can use the api key `special-key` to test the authorization filters. [Learn about Swagger](http://swagger.io) or join the IRC channel `#swagger` on irc.freenode.net.
version: '1.0.0'
For this sample, you can use the api key `special-key` to test the authorization filters
version: "1.0.0"
title: Swagger Petstore title: Swagger Petstore
termsOfService: http://swagger.io/terms/ termsOfService: http://helloreverb.com/terms/
contact: contact:
email: apiteam@swagger.io name: apiteam@swagger.io
license: license:
name: Apache 2.0 name: Apache 2.0
url: http://www.apache.org/licenses/LICENSE-2.0.html url: http://www.apache.org/licenses/LICENSE-2.0.html
host: petstore.swagger.io host: petstore.swagger.io
basePath: /v2 basePath: /v2
tags:
- name: pet
description: Everything about your Pets
externalDocs:
description: Find out more
url: http://swagger.io
- name: store
description: Access to Petstore orders
- name: user
description: Operations about user
externalDocs:
description: Find out more about our store
url: http://swagger.io
schemes: schemes:
- http - http
paths: paths:
/pet: /pets:
post: post:
tags: tags:
- pet - pet
summary: Add a new pet to the store summary: Add a new pet to the store
description: ""
operationId: addPet operationId: addPet
consumes: consumes:
- application/json - application/json
- application/xml - application/xml
produces: produces:
- application/xml
- application/json - application/json
- application/xml
parameters: parameters:
- in: body - in: body
name: body name: body
description: Pet object that needs to be added to the store description: Pet object that needs to be added to the store
required: true required: false
schema: schema:
$ref: '#/definitions/Pet' $ref: "#/definitions/Pet"
responses: responses:
405: "405":
description: Invalid input description: Invalid input
security: security:
- petstore_auth: - petstore_auth:
- write:pets - write_pets
- read:pets - read_pets
put: put:
tags: tags:
- pet - pet
summary: Update an existing pet summary: Update an existing pet
description: ""
operationId: updatePet operationId: updatePet
consumes: consumes:
- application/json - application/json
- application/xml - application/xml
produces: produces:
- application/xml
- application/json - application/json
- application/xml
parameters: parameters:
- in: body - in: body
name: body name: body
description: Pet object that needs to be added to the store description: Pet object that needs to be added to the store
required: true required: false
schema: schema:
$ref: '#/definitions/Pet' $ref: "#/definitions/Pet"
responses: responses:
400: "405":
description: Invalid ID supplied
404:
description: Pet not found
405:
description: Validation exception description: Validation exception
"404":
description: Pet not found
"400":
description: Invalid ID supplied
security: security:
- petstore_auth: - petstore_auth:
- write:pets - write_pets
- read:pets - read_pets
/pet/findByStatus: /pets/findByStatus:
get: get:
tags: tags:
- pet - pet
summary: Finds Pets by status summary: Finds Pets by status
description: Multiple status values can be provided with comma separated strings description: Multiple status values can be provided with comma seperated strings
operationId: findPetsByStatus operationId: findPetsByStatus
produces: produces:
- application/xml
- application/json - application/json
- application/xml
parameters: parameters:
- name: status - in: query
in: query name: status
description: Status values that need to be considered for filter description: Status values that need to be considered for filter
required: true required: false
type: array type: array
items: items:
type: string type: string
enum:
- available
- pending
- sold
default: available
collectionFormat: multi collectionFormat: multi
responses: responses:
200: "200":
description: successful operation description: successful operation
schema: schema:
type: array type: array
items: items:
$ref: '#/definitions/Pet' $ref: "#/definitions/Pet"
400: "400":
description: Invalid status value description: Invalid status value
security: security:
- petstore_auth: - petstore_auth:
- write:pets - write_pets
- read:pets - read_pets
/pet/findByTags: /pets/findByTags:
get: get:
tags: tags:
- pet - pet
summary: Finds Pets by tags summary: Finds Pets by tags
description: | description: Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.
Muliple tags can be provided with comma separated strings. Use
tag1, tag2, tag3 for testing.
operationId: findPetsByTags operationId: findPetsByTags
produces: produces:
- application/xml
- application/json - application/json
- application/xml
parameters: parameters:
- name: tags - in: query
in: query name: tags
description: Tags to filter by description: Tags to filter by
required: true required: false
type: array type: array
items: items:
type: string type: string
collectionFormat: multi collectionFormat: multi
responses: responses:
200: "200":
description: successful operation description: successful operation
schema: schema:
type: array type: array
items: items:
$ref: '#/definitions/Pet' $ref: "#/definitions/Pet"
400: "400":
description: Invalid tag value description: Invalid tag value
security: security:
- petstore_auth: - petstore_auth:
- write:pets - write_pets
- read:pets - read_pets
deprecated: true /pets/{petId}:
/pet/{petId}:
get: get:
tags: tags:
- pet - pet
summary: Find pet by ID summary: Find pet by ID
description: Returns a single pet description: Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions
operationId: getPetById operationId: getPetById
produces: produces:
- application/xml
- application/json - application/json
- application/xml
parameters: parameters:
- name: petId - in: path
in: path name: petId
description: ID of pet to return description: ID of pet that needs to be fetched
required: true required: true
type: integer type: integer
format: int64 format: int64
responses: responses:
200: "404":
description: Pet not found
"200":
description: successful operation description: successful operation
schema: schema:
$ref: '#/definitions/Pet' $ref: "#/definitions/Pet"
400: "400":
description: Invalid ID supplied description: Invalid ID supplied
404:
description: Pet not found
security: security:
- api_key: [] - api_key: []
- petstore_auth:
- write_pets
- read_pets
post: post:
tags: tags:
- pet - pet
summary: Updates a pet in the store with form data summary: Updates a pet in the store with form data
description: description: ""
operationId: updatePetWithForm operationId: updatePetWithForm
consumes: consumes:
- application/x-www-form-urlencoded - application/x-www-form-urlencoded
produces: produces:
- application/xml
- application/json - application/json
- application/xml
parameters: parameters:
- name: petId - in: path
in: path name: petId
description: ID of pet that needs to be updated description: ID of pet that needs to be updated
required: true required: true
type: integer
format: int64
- name: name
in: formData
description: Updated name of the pet
required: false
type: string type: string
- name: status - in: formData
in: formData name: name
description: Updated name of the pet
required: true
type: string
- in: formData
name: status
description: Updated status of the pet description: Updated status of the pet
required: false required: true
type: string type: string
responses: responses:
405: "405":
description: Invalid input description: Invalid input
security: security:
- petstore_auth: - petstore_auth:
- write:pets - write_pets
- read:pets - read_pets
delete: delete:
tags: tags:
- pet - pet
summary: Deletes a pet summary: Deletes a pet
description: ""
operationId: deletePet operationId: deletePet
produces: produces:
- application/xml
- application/json - application/json
- application/xml
parameters: parameters:
- name: api_key - in: header
in: header name: api_key
required: false description: ""
required: true
type: string type: string
- name: petId - in: path
in: path name: petId
description: Pet id to delete description: Pet id to delete
required: true required: true
type: integer type: integer
format: int64 format: int64
responses: responses:
400: "400":
description: Invalid ID supplied description: Invalid pet value
404:
description: Pet not found
security: security:
- petstore_auth: - petstore_auth:
- write:pets - write_pets
- read:pets - read_pets
/pet/{petId}/uploadImage: /stores/order:
post:
tags:
- pet
summary: uploads an image
operationId: uploadFile
consumes:
- multipart/form-data
produces:
- application/json
parameters:
- name: petId
in: path
description: ID of pet to update
required: true
type: integer
format: int64
- name: additionalMetadata
in: formData
description: Additional data to pass to server
required: false
type: string
- name: file
in: formData
description: file to upload
required: false
type: file
responses:
200:
description: successful operation
schema:
$ref: '#/definitions/ApiResponse'
security:
- petstore_auth:
- write:pets
- read:pets
/store/inventory:
get:
tags:
- store
summary: Returns pet inventories by status
description: Returns a map of status codes to quantities
operationId: getInventory
produces:
- application/json
parameters: []
responses:
200:
description: successful operation
schema:
type: object
additionalProperties:
type: integer
format: int32
security:
- api_key: []
/store/order:
post: post:
tags: tags:
- store - store
summary: Place an order for a pet summary: Place an order for a pet
description: ""
operationId: placeOrder operationId: placeOrder
produces: produces:
- application/xml
- application/json - application/json
- application/xml
parameters: parameters:
- in: body - in: body
name: body name: body
description: order placed for purchasing the pet description: order placed for purchasing the pet
required: true required: false
schema: schema:
$ref: '#/definitions/Order' $ref: "#/definitions/Order"
responses: responses:
200: "200":
description: successful operation description: successful operation
schema: schema:
$ref: '#/definitions/Order' $ref: "#/definitions/Order"
400: "400":
description: Invalid Order description: Invalid Order
/store/order/{orderId}: /stores/order/{orderId}:
get: get:
tags: tags:
- store - store
summary: Find purchase order by ID summary: Find purchase order by ID
description: | description: For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
For valid response try integer IDs with value >= 1 and <= 10.
Other values will generated exceptions
operationId: getOrderById operationId: getOrderById
produces: produces:
- application/xml
- application/json - application/json
- application/xml
parameters: parameters:
- name: orderId - in: path
in: path name: orderId
description: ID of pet that needs to be fetched description: ID of pet that needs to be fetched
required: true required: true
type: integer type: string
maximum: 10.0
minimum: 1.0
format: int64
responses: responses:
200: "404":
description: Order not found
"200":
description: successful operation description: successful operation
schema: schema:
$ref: '#/definitions/Order' $ref: "#/definitions/Order"
400: "400":
description: Invalid ID supplied description: Invalid ID supplied
404:
description: Order not found
delete: delete:
tags: tags:
- store - store
summary: Delete purchase order by ID summary: Delete purchase order by ID
description: For valid response try integer IDs with positive integer value.\ description: For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
\ Negative or non-integer values will generate API errors
operationId: deleteOrder operationId: deleteOrder
produces: produces:
- application/xml
- application/json - application/json
- application/xml
parameters: parameters:
- name: orderId - in: path
in: path name: orderId
description: ID of the order that needs to be deleted description: ID of the order that needs to be deleted
required: true required: true
type: integer type: string
minimum: 1.0
format: int64
responses: responses:
400: "404":
description: Invalid ID supplied
404:
description: Order not found description: Order not found
/user: "400":
description: Invalid ID supplied
/users:
post: post:
tags: tags:
- user - user
@ -388,134 +310,128 @@ paths:
description: This can only be done by the logged in user. description: This can only be done by the logged in user.
operationId: createUser operationId: createUser
produces: produces:
- application/xml
- application/json - application/json
- application/xml
parameters: parameters:
- in: body - in: body
name: body name: body
description: Created user object description: Created user object
required: true required: false
schema: schema:
$ref: '#/definitions/User' $ref: "#/definitions/User"
responses: responses:
default: default:
description: successful operation description: successful operation
/user/createWithArray: /users/createWithArray:
post: post:
tags: tags:
- user - user
summary: Creates list of users with given input array summary: Creates list of users with given input array
description: ""
operationId: createUsersWithArrayInput operationId: createUsersWithArrayInput
produces: produces:
- application/xml
- application/json - application/json
- application/xml
parameters: parameters:
- in: body - in: body
name: body name: body
description: List of user object description: List of user object
required: true required: false
schema: schema:
type: array type: array
items: items:
$ref: '#/definitions/User' $ref: "#/definitions/User"
responses: responses:
default: default:
description: successful operation description: successful operation
/user/createWithList: /users/createWithList:
post: post:
tags: tags:
- user - user
summary: Creates list of users with given input array summary: Creates list of users with given input array
description: ""
operationId: createUsersWithListInput operationId: createUsersWithListInput
produces: produces:
- application/xml
- application/json - application/json
- application/xml
parameters: parameters:
- in: body - in: body
name: body name: body
description: List of user object description: List of user object
required: true required: false
schema: schema:
type: array type: array
items: items:
$ref: '#/definitions/User' $ref: "#/definitions/User"
responses: responses:
default: default:
description: successful operation description: successful operation
/user/login: /users/login:
get: get:
tags: tags:
- user - user
summary: Logs user into the system summary: Logs user into the system
description: ""
operationId: loginUser operationId: loginUser
produces: produces:
- application/xml
- application/json - application/json
- application/xml
parameters: parameters:
- name: username - in: query
in: query name: username
description: The user name for login description: The user name for login
required: true required: false
type: string type: string
- name: password - in: query
in: query name: password
description: The password for login in clear text description: The password for login in clear text
required: true required: false
type: string type: string
responses: responses:
200: "200":
description: successful operation description: successful operation
schema: schema:
type: string type: string
headers: "400":
X-Rate-Limit:
type: integer
format: int32
description: calls per hour allowed by the user
X-Expires-After:
type: string
format: date-time
description: date in UTC when token expires
400:
description: Invalid username/password supplied description: Invalid username/password supplied
/user/logout: /users/logout:
get: get:
tags: tags:
- user - user
summary: Logs out current logged in user session summary: Logs out current logged in user session
description: description: ""
operationId: logoutUser operationId: logoutUser
produces: produces:
- application/xml
- application/json - application/json
parameters: [] - application/xml
responses: responses:
default: default:
description: successful operation description: successful operation
/user/{username}: /users/{username}:
get: get:
tags: tags:
- user - user
summary: Get user by user name summary: Get user by user name
description: ""
operationId: getUserByName operationId: getUserByName
produces: produces:
- application/xml
- application/json - application/json
- application/xml
parameters: parameters:
- name: username - in: path
in: path name: username
description: The name that needs to be fetched. Use user1 for testing. description: The name that needs to be fetched. Use user1 for testing.
required: true required: true
type: string type: string
responses: responses:
200: "404":
description: User not found
"200":
description: successful operation description: successful operation
schema: schema:
$ref: '#/definitions/User' $ref: "#/definitions/User"
400: "400":
description: Invalid username supplied description: Invalid username supplied
404:
description: User not found
put: put:
tags: tags:
- user - user
@ -523,25 +439,25 @@ paths:
description: This can only be done by the logged in user. description: This can only be done by the logged in user.
operationId: updateUser operationId: updateUser
produces: produces:
- application/xml
- application/json - application/json
- application/xml
parameters: parameters:
- name: username - in: path
in: path name: username
description: name that need to be updated description: name that need to be deleted
required: true required: true
type: string type: string
- in: body - in: body
name: body name: body
description: Updated user object description: Updated user object
required: true required: false
schema: schema:
$ref: '#/definitions/User' $ref: "#/definitions/User"
responses: responses:
400: "404":
description: Invalid user supplied
404:
description: User not found description: User not found
"400":
description: Invalid user supplied
delete: delete:
tags: tags:
- user - user
@ -549,59 +465,32 @@ paths:
description: This can only be done by the logged in user. description: This can only be done by the logged in user.
operationId: deleteUser operationId: deleteUser
produces: produces:
- application/xml
- application/json - application/json
- application/xml
parameters: parameters:
- name: username - in: path
in: path name: username
description: The name that needs to be deleted description: The name that needs to be deleted
required: true required: true
type: string type: string
responses: responses:
400: "404":
description: Invalid username supplied
404:
description: User not found description: User not found
"400":
description: Invalid username supplied
securityDefinitions: securityDefinitions:
petstore_auth:
type: oauth2
authorizationUrl: http://petstore.swagger.io/oauth/dialog
flow: implicit
scopes:
write:pets: modify pets in your account
read:pets: read your pets
api_key: api_key:
type: apiKey type: apiKey
name: api_key name: api_key
in: header in: header
petstore_auth:
type: oauth2
authorizationUrl: http://petstore.swagger.io/api/oauth/dialog
flow: implicit
scopes:
write_pets: modify pets in your account
read_pets: read your pets
definitions: definitions:
Order:
type: object
properties:
id:
type: integer
format: int64
petId:
type: integer
format: int64
quantity:
type: integer
format: int32
shipDate:
type: string
format: date-time
status:
type: string
description: Order Status
enum:
- placed
- approved
- delivered
complete:
type: boolean
default: false
xml:
name: Order
User: User:
type: object type: object
properties: properties:
@ -624,8 +513,6 @@ definitions:
type: integer type: integer
format: int32 format: int32
description: User Status description: User Status
xml:
name: User
Category: Category:
type: object type: object
properties: properties:
@ -634,18 +521,6 @@ definitions:
format: int64 format: int64
name: name:
type: string type: string
xml:
name: Category
Tag:
type: object
properties:
id:
type: integer
format: int64
name:
type: string
xml:
name: Tag
Pet: Pet:
type: object type: object
required: required:
@ -656,43 +531,46 @@ definitions:
type: integer type: integer
format: int64 format: int64
category: category:
$ref: '#/definitions/Category' $ref: "#/definitions/Category"
name: name:
type: string type: string
example: doggie example: doggie
photoUrls: photoUrls:
type: array type: array
xml:
name: photoUrl
wrapped: true
items: items:
type: string type: string
tags: tags:
type: array type: array
xml:
name: tag
wrapped: true
items: items:
$ref: '#/definitions/Tag' $ref: "#/definitions/Tag"
status: status:
type: string type: string
description: pet status in the store description: pet status in the store
enum: Tag:
- available
- pending
- sold
xml:
name: Pet
ApiResponse:
type: object type: object
properties: properties:
code: id:
type: integer
format: int64
name:
type: string
Order:
type: object
properties:
id:
type: integer
format: int64
petId:
type: integer
format: int64
quantity:
type: integer type: integer
format: int32 format: int32
type: shipDate:
type: string type: string
message: format: date-time
status:
type: string type: string
externalDocs: description: Order Status
description: Find out more about Swagger complete:
url: http://swagger.io type: boolean

View File

@ -1,39 +1,12 @@
require 'json' require 'json'
MyApp.add_route('PUT', '/v2/pet', { MyApp.add_route('POST', '/v2/pets', {
"resourcePath" => "/Pet",
"summary" => "Update an existing pet",
"nickname" => "update_pet",
"responseClass" => "void",
"endpoint" => "/pet",
"notes" => "",
"parameters" => [
{
"name" => "body",
"description" => "Pet object that needs to be added to the store",
"dataType" => "Pet",
"paramType" => "body",
}
]}) do
cross_origin
# the guts live here
{"message" => "yes, it worked"}.to_json
end
MyApp.add_route('POST', '/v2/pet', {
"resourcePath" => "/Pet", "resourcePath" => "/Pet",
"summary" => "Add a new pet to the store", "summary" => "Add a new pet to the store",
"nickname" => "add_pet", "nickname" => "add_pet",
"responseClass" => "void", "responseClass" => "void",
"endpoint" => "/pet", "endpoint" => "/pets",
"notes" => "", "notes" => "",
"parameters" => [ "parameters" => [
@ -55,126 +28,12 @@ MyApp.add_route('POST', '/v2/pet', {
end end
MyApp.add_route('GET', '/v2/pet/findByStatus', { MyApp.add_route('DELETE', '/v2/pets/{petId}', {
"resourcePath" => "/Pet",
"summary" => "Finds Pets by status",
"nickname" => "find_pets_by_status",
"responseClass" => "array[Pet]",
"endpoint" => "/pet/findByStatus",
"notes" => "Multiple status values can be provided with comma seperated strings",
"parameters" => [
{
"name" => "status",
"description" => "Status values that need to be considered for filter",
"dataType" => "array[string]",
"paramType" => "query",
"collectionFormat" => "multi",
"allowableValues" => "",
"defaultValue" => "available"
},
]}) do
cross_origin
# the guts live here
{"message" => "yes, it worked"}.to_json
end
MyApp.add_route('GET', '/v2/pet/findByTags', {
"resourcePath" => "/Pet",
"summary" => "Finds Pets by tags",
"nickname" => "find_pets_by_tags",
"responseClass" => "array[Pet]",
"endpoint" => "/pet/findByTags",
"notes" => "Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.",
"parameters" => [
{
"name" => "tags",
"description" => "Tags to filter by",
"dataType" => "array[string]",
"paramType" => "query",
"collectionFormat" => "multi",
"allowableValues" => "",
},
]}) do
cross_origin
# the guts live here
{"message" => "yes, it worked"}.to_json
end
MyApp.add_route('GET', '/v2/pet/{petId}', {
"resourcePath" => "/Pet",
"summary" => "Find pet by ID",
"nickname" => "get_pet_by_id",
"responseClass" => "Pet",
"endpoint" => "/pet/{petId}",
"notes" => "Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions",
"parameters" => [
{
"name" => "pet_id",
"description" => "ID of pet that needs to be fetched",
"dataType" => "int",
"paramType" => "path",
},
]}) do
cross_origin
# the guts live here
{"message" => "yes, it worked"}.to_json
end
MyApp.add_route('POST', '/v2/pet/{petId}', {
"resourcePath" => "/Pet",
"summary" => "Updates a pet in the store with form data",
"nickname" => "update_pet_with_form",
"responseClass" => "void",
"endpoint" => "/pet/{petId}",
"notes" => "",
"parameters" => [
{
"name" => "pet_id",
"description" => "ID of pet that needs to be updated",
"dataType" => "string",
"paramType" => "path",
},
]}) do
cross_origin
# the guts live here
{"message" => "yes, it worked"}.to_json
end
MyApp.add_route('DELETE', '/v2/pet/{petId}', {
"resourcePath" => "/Pet", "resourcePath" => "/Pet",
"summary" => "Deletes a pet", "summary" => "Deletes a pet",
"nickname" => "delete_pet", "nickname" => "delete_pet",
"responseClass" => "void", "responseClass" => "void",
"endpoint" => "/pet/{petId}", "endpoint" => "/pets/{petId}",
"notes" => "", "notes" => "",
"parameters" => [ "parameters" => [
@ -203,25 +62,139 @@ MyApp.add_route('DELETE', '/v2/pet/{petId}', {
end end
MyApp.add_route('POST', '/v2/pet/{petId}/uploadImage', { MyApp.add_route('GET', '/v2/pets/findByStatus', {
"resourcePath" => "/Pet", "resourcePath" => "/Pet",
"summary" => "uploads an image", "summary" => "Finds Pets by status",
"nickname" => "upload_file", "nickname" => "find_pets_by_status",
"responseClass" => "void", "responseClass" => "array[Pet]",
"endpoint" => "/pet/{petId}/uploadImage", "endpoint" => "/pets/findByStatus",
"notes" => "", "notes" => "Multiple status values can be provided with comma seperated strings",
"parameters" => [
{
"name" => "status",
"description" => "Status values that need to be considered for filter",
"dataType" => "array[string]",
"paramType" => "query",
"collectionFormat" => "multi",
"allowableValues" => "",
},
]}) do
cross_origin
# the guts live here
{"message" => "yes, it worked"}.to_json
end
MyApp.add_route('GET', '/v2/pets/findByTags', {
"resourcePath" => "/Pet",
"summary" => "Finds Pets by tags",
"nickname" => "find_pets_by_tags",
"responseClass" => "array[Pet]",
"endpoint" => "/pets/findByTags",
"notes" => "Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.",
"parameters" => [
{
"name" => "tags",
"description" => "Tags to filter by",
"dataType" => "array[string]",
"paramType" => "query",
"collectionFormat" => "multi",
"allowableValues" => "",
},
]}) do
cross_origin
# the guts live here
{"message" => "yes, it worked"}.to_json
end
MyApp.add_route('GET', '/v2/pets/{petId}', {
"resourcePath" => "/Pet",
"summary" => "Find pet by ID",
"nickname" => "get_pet_by_id",
"responseClass" => "Pet",
"endpoint" => "/pets/{petId}",
"notes" => "Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions",
"parameters" => [ "parameters" => [
{ {
"name" => "pet_id", "name" => "pet_id",
"description" => "ID of pet to update", "description" => "ID of pet that needs to be fetched",
"dataType" => "int", "dataType" => "int",
"paramType" => "path", "paramType" => "path",
}, },
]}) do
cross_origin
# the guts live here
{"message" => "yes, it worked"}.to_json
end
MyApp.add_route('PUT', '/v2/pets', {
"resourcePath" => "/Pet",
"summary" => "Update an existing pet",
"nickname" => "update_pet",
"responseClass" => "void",
"endpoint" => "/pets",
"notes" => "",
"parameters" => [
{
"name" => "body",
"description" => "Pet object that needs to be added to the store",
"dataType" => "Pet",
"paramType" => "body",
}
]}) do
cross_origin
# the guts live here
{"message" => "yes, it worked"}.to_json
end
MyApp.add_route('POST', '/v2/pets/{petId}', {
"resourcePath" => "/Pet",
"summary" => "Updates a pet in the store with form data",
"nickname" => "update_pet_with_form",
"responseClass" => "void",
"endpoint" => "/pets/{petId}",
"notes" => "",
"parameters" => [
{
"name" => "pet_id",
"description" => "ID of pet that needs to be updated",
"dataType" => "string",
"paramType" => "path",
},
]}) do ]}) do
cross_origin cross_origin
# the guts live here # the guts live here

View File

@ -1,44 +1,24 @@
require 'json' require 'json'
MyApp.add_route('GET', '/v2/store/inventory', { MyApp.add_route('DELETE', '/v2/stores/order/{orderId}', {
"resourcePath" => "/Store", "resourcePath" => "/Store",
"summary" => "Returns pet inventories by status", "summary" => "Delete purchase order by ID",
"nickname" => "get_inventory", "nickname" => "delete_order",
"responseClass" => "map[string,int]", "responseClass" => "void",
"endpoint" => "/store/inventory", "endpoint" => "/stores/order/{orderId}",
"notes" => "Returns a map of status codes to quantities", "notes" => "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors",
"parameters" => [ "parameters" => [
]}) do
cross_origin
# the guts live here
{"message" => "yes, it worked"}.to_json
end
MyApp.add_route('POST', '/v2/store/order', {
"resourcePath" => "/Store",
"summary" => "Place an order for a pet",
"nickname" => "place_order",
"responseClass" => "Order",
"endpoint" => "/store/order",
"notes" => "",
"parameters" => [
{ {
"name" => "body", "name" => "order_id",
"description" => "order placed for purchasing the pet", "description" => "ID of the order that needs to be deleted",
"dataType" => "Order", "dataType" => "string",
"paramType" => "body", "paramType" => "path",
} },
]}) do ]}) do
cross_origin cross_origin
@ -48,12 +28,12 @@ MyApp.add_route('POST', '/v2/store/order', {
end end
MyApp.add_route('GET', '/v2/store/order/{orderId}', { MyApp.add_route('GET', '/v2/stores/order/{orderId}', {
"resourcePath" => "/Store", "resourcePath" => "/Store",
"summary" => "Find purchase order by ID", "summary" => "Find purchase order by ID",
"nickname" => "get_order_by_id", "nickname" => "get_order_by_id",
"responseClass" => "Order", "responseClass" => "Order",
"endpoint" => "/store/order/{orderId}", "endpoint" => "/stores/order/{orderId}",
"notes" => "For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions", "notes" => "For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions",
"parameters" => [ "parameters" => [
@ -75,24 +55,24 @@ MyApp.add_route('GET', '/v2/store/order/{orderId}', {
end end
MyApp.add_route('DELETE', '/v2/store/order/{orderId}', { MyApp.add_route('POST', '/v2/stores/order', {
"resourcePath" => "/Store", "resourcePath" => "/Store",
"summary" => "Delete purchase order by ID", "summary" => "Place an order for a pet",
"nickname" => "delete_order", "nickname" => "place_order",
"responseClass" => "void", "responseClass" => "Order",
"endpoint" => "/store/order/{orderId}", "endpoint" => "/stores/order",
"notes" => "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors", "notes" => "",
"parameters" => [ "parameters" => [
{ {
"name" => "order_id", "name" => "body",
"description" => "ID of the order that needs to be deleted", "description" => "order placed for purchasing the pet",
"dataType" => "string", "dataType" => "Order",
"paramType" => "path", "paramType" => "body",
}, }
]}) do ]}) do
cross_origin cross_origin

View File

@ -1,12 +1,12 @@
require 'json' require 'json'
MyApp.add_route('POST', '/v2/user', { MyApp.add_route('POST', '/v2/users', {
"resourcePath" => "/User", "resourcePath" => "/User",
"summary" => "Create user", "summary" => "Create user",
"nickname" => "create_user", "nickname" => "create_user",
"responseClass" => "void", "responseClass" => "void",
"endpoint" => "/user", "endpoint" => "/users",
"notes" => "This can only be done by the logged in user.", "notes" => "This can only be done by the logged in user.",
"parameters" => [ "parameters" => [
@ -28,12 +28,12 @@ MyApp.add_route('POST', '/v2/user', {
end end
MyApp.add_route('POST', '/v2/user/createWithArray', { MyApp.add_route('POST', '/v2/users/createWithArray', {
"resourcePath" => "/User", "resourcePath" => "/User",
"summary" => "Creates list of users with given input array", "summary" => "Creates list of users with given input array",
"nickname" => "create_users_with_array_input", "nickname" => "create_users_with_array_input",
"responseClass" => "void", "responseClass" => "void",
"endpoint" => "/user/createWithArray", "endpoint" => "/users/createWithArray",
"notes" => "", "notes" => "",
"parameters" => [ "parameters" => [
@ -55,12 +55,12 @@ MyApp.add_route('POST', '/v2/user/createWithArray', {
end end
MyApp.add_route('POST', '/v2/user/createWithList', { MyApp.add_route('POST', '/v2/users/createWithList', {
"resourcePath" => "/User", "resourcePath" => "/User",
"summary" => "Creates list of users with given input array", "summary" => "Creates list of users with given input array",
"nickname" => "create_users_with_list_input", "nickname" => "create_users_with_list_input",
"responseClass" => "void", "responseClass" => "void",
"endpoint" => "/user/createWithList", "endpoint" => "/users/createWithList",
"notes" => "", "notes" => "",
"parameters" => [ "parameters" => [
@ -82,12 +82,66 @@ MyApp.add_route('POST', '/v2/user/createWithList', {
end end
MyApp.add_route('GET', '/v2/user/login', { MyApp.add_route('DELETE', '/v2/users/{username}', {
"resourcePath" => "/User",
"summary" => "Delete user",
"nickname" => "delete_user",
"responseClass" => "void",
"endpoint" => "/users/{username}",
"notes" => "This can only be done by the logged in user.",
"parameters" => [
{
"name" => "username",
"description" => "The name that needs to be deleted",
"dataType" => "string",
"paramType" => "path",
},
]}) do
cross_origin
# the guts live here
{"message" => "yes, it worked"}.to_json
end
MyApp.add_route('GET', '/v2/users/{username}', {
"resourcePath" => "/User",
"summary" => "Get user by user name",
"nickname" => "get_user_by_name",
"responseClass" => "User",
"endpoint" => "/users/{username}",
"notes" => "",
"parameters" => [
{
"name" => "username",
"description" => "The name that needs to be fetched. Use user1 for testing.",
"dataType" => "string",
"paramType" => "path",
},
]}) do
cross_origin
# the guts live here
{"message" => "yes, it worked"}.to_json
end
MyApp.add_route('GET', '/v2/users/login', {
"resourcePath" => "/User", "resourcePath" => "/User",
"summary" => "Logs user into the system", "summary" => "Logs user into the system",
"nickname" => "login_user", "nickname" => "login_user",
"responseClass" => "string", "responseClass" => "string",
"endpoint" => "/user/login", "endpoint" => "/users/login",
"notes" => "", "notes" => "",
"parameters" => [ "parameters" => [
@ -122,12 +176,12 @@ MyApp.add_route('GET', '/v2/user/login', {
end end
MyApp.add_route('GET', '/v2/user/logout', { MyApp.add_route('GET', '/v2/users/logout', {
"resourcePath" => "/User", "resourcePath" => "/User",
"summary" => "Logs out current logged in user session", "summary" => "Logs out current logged in user session",
"nickname" => "logout_user", "nickname" => "logout_user",
"responseClass" => "void", "responseClass" => "void",
"endpoint" => "/user/logout", "endpoint" => "/users/logout",
"notes" => "", "notes" => "",
"parameters" => [ "parameters" => [
@ -142,39 +196,12 @@ MyApp.add_route('GET', '/v2/user/logout', {
end end
MyApp.add_route('GET', '/v2/user/{username}', { MyApp.add_route('PUT', '/v2/users/{username}', {
"resourcePath" => "/User",
"summary" => "Get user by user name",
"nickname" => "get_user_by_name",
"responseClass" => "User",
"endpoint" => "/user/{username}",
"notes" => "",
"parameters" => [
{
"name" => "username",
"description" => "The name that needs to be fetched. Use user1 for testing.",
"dataType" => "string",
"paramType" => "path",
},
]}) do
cross_origin
# the guts live here
{"message" => "yes, it worked"}.to_json
end
MyApp.add_route('PUT', '/v2/user/{username}', {
"resourcePath" => "/User", "resourcePath" => "/User",
"summary" => "Updated user", "summary" => "Updated user",
"nickname" => "update_user", "nickname" => "update_user",
"responseClass" => "void", "responseClass" => "void",
"endpoint" => "/user/{username}", "endpoint" => "/users/{username}",
"notes" => "This can only be done by the logged in user.", "notes" => "This can only be done by the logged in user.",
"parameters" => [ "parameters" => [
@ -202,30 +229,3 @@ MyApp.add_route('PUT', '/v2/user/{username}', {
{"message" => "yes, it worked"}.to_json {"message" => "yes, it worked"}.to_json
end end
MyApp.add_route('DELETE', '/v2/user/{username}', {
"resourcePath" => "/User",
"summary" => "Delete user",
"nickname" => "delete_user",
"responseClass" => "void",
"endpoint" => "/user/{username}",
"notes" => "This can only be done by the logged in user.",
"parameters" => [
{
"name" => "username",
"description" => "The name that needs to be deleted",
"dataType" => "string",
"paramType" => "path",
},
]}) do
cross_origin
# the guts live here
{"message" => "yes, it worked"}.to_json
end

View File

@ -39,7 +39,7 @@ class Swaggering < Sinatra::Base
def self.add_route(method, path, swag={}, opts={}, &block) def self.add_route(method, path, swag={}, opts={}, &block)
#fullPath = swag["resourcePath"].to_s + @@configuration.format_specifier + path #fullPath = swag["resourcePath"].to_s + @@configuration.format_specifier + path
fullPath = path.gsub(/{(.*)}/, ':\1') fullPath = path.gsub(/{(.*?)}/, ':\1')
accepted = case method.to_s.downcase accepted = case method.to_s.downcase
when 'get' when 'get'

View File

@ -1,15 +1,14 @@
--- ---
swagger: "2.0" swagger: "2.0"
info: info:
description: "This is a sample server Petstore server. You can find out more about\ description: "This is a sample server Petstore server.\n\n[Learn about Swagger](http://swagger.io)\
\ Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net,\ \ or join the IRC channel `#swagger` on irc.freenode.net.\n\nFor this sample,\
\ #swagger. For this sample, you can use the api key \"special-key\" to test\ \ you can use the api key `special-key` to test the authorization filters\n"
\ the authorization filters"
version: "1.0.0" version: "1.0.0"
title: "Swagger Petstore" title: "Swagger Petstore"
termsOfService: "http://swagger.io/terms/" termsOfService: "http://helloreverb.com/terms/"
contact: contact:
email: "apiteam@swagger.io" name: "apiteam@swagger.io"
license: license:
name: "Apache 2.0" name: "Apache 2.0"
url: "http://www.apache.org/licenses/LICENSE-2.0.html" url: "http://www.apache.org/licenses/LICENSE-2.0.html"
@ -18,7 +17,7 @@ basePath: "/v2"
schemes: schemes:
- "http" - "http"
paths: paths:
/pet: /pets:
post: post:
tags: tags:
- "pet" - "pet"
@ -43,8 +42,8 @@ paths:
description: "Invalid input" description: "Invalid input"
security: security:
- petstore_auth: - petstore_auth:
- "write:pets" - "write_pets"
- "read:pets" - "read_pets"
put: put:
tags: tags:
- "pet" - "pet"
@ -73,9 +72,9 @@ paths:
description: "Validation exception" description: "Validation exception"
security: security:
- petstore_auth: - petstore_auth:
- "write:pets" - "write_pets"
- "read:pets" - "read_pets"
/pet/findByStatus: /pets/findByStatus:
get: get:
tags: tags:
- "pet" - "pet"
@ -94,7 +93,6 @@ paths:
items: items:
type: "string" type: "string"
collectionFormat: "multi" collectionFormat: "multi"
default: "available"
responses: responses:
200: 200:
description: "successful operation" description: "successful operation"
@ -106,9 +104,9 @@ paths:
description: "Invalid status value" description: "Invalid status value"
security: security:
- petstore_auth: - petstore_auth:
- "write:pets" - "write_pets"
- "read:pets" - "read_pets"
/pet/findByTags: /pets/findByTags:
get: get:
tags: tags:
- "pet" - "pet"
@ -139,9 +137,9 @@ paths:
description: "Invalid tag value" description: "Invalid tag value"
security: security:
- petstore_auth: - petstore_auth:
- "write:pets" - "write_pets"
- "read:pets" - "read_pets"
/pet/{petId}: /pets/{petId}:
get: get:
tags: tags:
- "pet" - "pet"
@ -171,8 +169,8 @@ paths:
security: security:
- api_key: [] - api_key: []
- petstore_auth: - petstore_auth:
- "write:pets" - "write_pets"
- "read:pets" - "read_pets"
post: post:
tags: tags:
- "pet" - "pet"
@ -193,20 +191,20 @@ paths:
- name: "name" - name: "name"
in: "formData" in: "formData"
description: "Updated name of the pet" description: "Updated name of the pet"
required: false required: true
type: "string" type: "string"
- name: "status" - name: "status"
in: "formData" in: "formData"
description: "Updated status of the pet" description: "Updated status of the pet"
required: false required: true
type: "string" type: "string"
responses: responses:
405: 405:
description: "Invalid input" description: "Invalid input"
security: security:
- petstore_auth: - petstore_auth:
- "write:pets" - "write_pets"
- "read:pets" - "read_pets"
delete: delete:
tags: tags:
- "pet" - "pet"
@ -220,7 +218,7 @@ paths:
- name: "api_key" - name: "api_key"
in: "header" in: "header"
description: "" description: ""
required: false required: true
type: "string" type: "string"
- name: "petId" - name: "petId"
in: "path" in: "path"
@ -233,66 +231,9 @@ paths:
description: "Invalid pet value" description: "Invalid pet value"
security: security:
- petstore_auth: - petstore_auth:
- "write:pets" - "write_pets"
- "read:pets" - "read_pets"
/pet/{petId}/uploadImage: /stores/order:
post:
tags:
- "pet"
summary: "uploads an image"
description: ""
operationId: "uploadFile"
consumes:
- "multipart/form-data"
produces:
- "application/json"
- "application/xml"
parameters:
- name: "petId"
in: "path"
description: "ID of pet to update"
required: true
type: "integer"
format: "int64"
- name: "additionalMetadata"
in: "formData"
description: "Additional data to pass to server"
required: false
type: "string"
- name: "file"
in: "formData"
description: "file to upload"
required: false
type: "file"
responses:
default:
description: "successful operation"
security:
- petstore_auth:
- "write:pets"
- "read:pets"
/store/inventory:
get:
tags:
- "store"
summary: "Returns pet inventories by status"
description: "Returns a map of status codes to quantities"
operationId: "getInventory"
produces:
- "application/json"
- "application/xml"
parameters: []
responses:
200:
description: "successful operation"
schema:
type: "object"
additionalProperties:
type: "integer"
format: "int32"
security:
- api_key: []
/store/order:
post: post:
tags: tags:
- "store" - "store"
@ -316,7 +257,7 @@ paths:
$ref: "#/definitions/Order" $ref: "#/definitions/Order"
400: 400:
description: "Invalid Order" description: "Invalid Order"
/store/order/{orderId}: /stores/order/{orderId}:
get: get:
tags: tags:
- "store" - "store"
@ -363,7 +304,7 @@ paths:
description: "Invalid ID supplied" description: "Invalid ID supplied"
404: 404:
description: "Order not found" description: "Order not found"
/user: /users:
post: post:
tags: tags:
- "user" - "user"
@ -383,7 +324,7 @@ paths:
responses: responses:
default: default:
description: "successful operation" description: "successful operation"
/user/createWithArray: /users/createWithArray:
post: post:
tags: tags:
- "user" - "user"
@ -405,7 +346,7 @@ paths:
responses: responses:
default: default:
description: "successful operation" description: "successful operation"
/user/createWithList: /users/createWithList:
post: post:
tags: tags:
- "user" - "user"
@ -427,7 +368,7 @@ paths:
responses: responses:
default: default:
description: "successful operation" description: "successful operation"
/user/login: /users/login:
get: get:
tags: tags:
- "user" - "user"
@ -455,7 +396,7 @@ paths:
type: "string" type: "string"
400: 400:
description: "Invalid username/password supplied" description: "Invalid username/password supplied"
/user/logout: /users/logout:
get: get:
tags: tags:
- "user" - "user"
@ -469,7 +410,7 @@ paths:
responses: responses:
default: default:
description: "successful operation" description: "successful operation"
/user/{username}: /users/{username}:
get: get:
tags: tags:
- "user" - "user"
@ -482,7 +423,7 @@ paths:
parameters: parameters:
- name: "username" - name: "username"
in: "path" in: "path"
description: "The name that needs to be fetched. Use user1 for testing. " description: "The name that needs to be fetched. Use user1 for testing."
required: true required: true
type: "string" type: "string"
responses: responses:
@ -490,16 +431,6 @@ paths:
description: "successful operation" description: "successful operation"
schema: schema:
$ref: "#/definitions/User" $ref: "#/definitions/User"
examples:
application/json:
id: 1
username: "johnp"
firstName: "John"
lastName: "Public"
email: "johnp@swagger.io"
password: "-secret-"
phone: "0123456789"
userStatus: 0
400: 400:
description: "Invalid username supplied" description: "Invalid username supplied"
404: 404:
@ -560,10 +491,11 @@ securityDefinitions:
authorizationUrl: "http://petstore.swagger.io/api/oauth/dialog" authorizationUrl: "http://petstore.swagger.io/api/oauth/dialog"
flow: "implicit" flow: "implicit"
scopes: scopes:
write:pets: "modify pets in your account" write_pets: "modify pets in your account"
read:pets: "read your pets" read_pets: "read your pets"
definitions: definitions:
User: User:
type: "object"
properties: properties:
id: id:
type: "integer" type: "integer"
@ -584,18 +516,16 @@ definitions:
type: "integer" type: "integer"
format: "int32" format: "int32"
description: "User Status" description: "User Status"
xml:
name: "User"
Category: Category:
type: "object"
properties: properties:
id: id:
type: "integer" type: "integer"
format: "int64" format: "int64"
name: name:
type: "string" type: "string"
xml:
name: "Category"
Pet: Pet:
type: "object"
required: required:
- "name" - "name"
- "photoUrls" - "photoUrls"
@ -610,37 +540,25 @@ definitions:
example: "doggie" example: "doggie"
photoUrls: photoUrls:
type: "array" type: "array"
xml:
name: "photoUrl"
wrapped: true
items: items:
type: "string" type: "string"
tags: tags:
type: "array" type: "array"
xml:
name: "tag"
wrapped: true
items: items:
$ref: "#/definitions/Tag" $ref: "#/definitions/Tag"
status: status:
type: "string" type: "string"
description: "pet status in the store" description: "pet status in the store"
enum:
- "available"
- "pending"
- "sold"
xml:
name: "Pet"
Tag: Tag:
type: "object"
properties: properties:
id: id:
type: "integer" type: "integer"
format: "int64" format: "int64"
name: name:
type: "string" type: "string"
xml:
name: "Tag"
Order: Order:
type: "object"
properties: properties:
id: id:
type: "integer" type: "integer"
@ -657,11 +575,5 @@ definitions:
status: status:
type: "string" type: "string"
description: "Order Status" description: "Order Status"
enum:
- "placed"
- "approved"
- "delivered"
complete: complete:
type: "boolean" type: "boolean"
xml:
name: "Order"