diff --git a/bin/sinatra-petstore-server.sh b/bin/sinatra-petstore-server.sh index 4f7e19cee39..7c99e9a068a 100755 --- a/bin/sinatra-petstore-server.sh +++ b/bin/sinatra-petstore-server.sh @@ -26,6 +26,6 @@ fi # 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" -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 diff --git a/modules/swagger-codegen/src/test/resources/2_0/petstore.json b/modules/swagger-codegen/src/test/resources/2_0/petstore.json index f248a42a49d..dfd7937242e 100644 --- a/modules/swagger-codegen/src/test/resources/2_0/petstore.json +++ b/modules/swagger-codegen/src/test/resources/2_0/petstore.json @@ -1301,7 +1301,7 @@ } }, "Return": { - "descripton": "Model for testing reserved words", + "description": "Model for testing reserved words", "properties": { "return": { "type": "integer", @@ -1313,7 +1313,7 @@ } }, "Name": { - "descripton": "Model for testing model name same as property name", + "description": "Model for testing model name same as property name", "properties": { "name": { "type": "integer", @@ -1329,7 +1329,7 @@ } }, "200_response": { - "descripton": "Model for testing model name starting with number", + "description": "Model for testing model name starting with number", "properties": { "name": { "type": "integer", diff --git a/modules/swagger-codegen/src/test/resources/2_0/petstore.yaml b/modules/swagger-codegen/src/test/resources/2_0/petstore.yaml index 394e0309fdc..cbfae8e4c45 100644 --- a/modules/swagger-codegen/src/test/resources/2_0/petstore.yaml +++ b/modules/swagger-codegen/src/test/resources/2_0/petstore.yaml @@ -1,607 +1,496 @@ -swagger: '2.0' +swagger: "2.0" info: description: | - This is a sample server Petstore server. You can find out more about - 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. - version: '1.0.0' + This is a sample server Petstore server. + + [Learn about Swagger](http://swagger.io) or join the IRC channel `#swagger` on irc.freenode.net. + + For this sample, you can use the api key `special-key` to test the authorization filters + version: "1.0.0" title: Swagger Petstore - termsOfService: http://swagger.io/terms/ + termsOfService: http://helloreverb.com/terms/ contact: - email: apiteam@swagger.io + name: apiteam@swagger.io license: name: Apache 2.0 url: http://www.apache.org/licenses/LICENSE-2.0.html host: petstore.swagger.io 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: -- http + - http paths: - /pet: + /pets: post: tags: - - pet + - pet summary: Add a new pet to the store + description: "" operationId: addPet consumes: - - application/json - - application/xml + - application/json + - application/xml produces: - - application/xml - - application/json + - application/json + - application/xml parameters: - - in: body - name: body - description: Pet object that needs to be added to the store - required: true - schema: - $ref: '#/definitions/Pet' + - in: body + name: body + description: Pet object that needs to be added to the store + required: false + schema: + $ref: "#/definitions/Pet" responses: - 405: + "405": description: Invalid input security: - - petstore_auth: - - write:pets - - read:pets + - petstore_auth: + - write_pets + - read_pets put: tags: - - pet + - pet summary: Update an existing pet + description: "" operationId: updatePet consumes: - - application/json - - application/xml + - application/json + - application/xml produces: - - application/xml - - application/json + - application/json + - application/xml parameters: - - in: body - name: body - description: Pet object that needs to be added to the store - required: true - schema: - $ref: '#/definitions/Pet' + - in: body + name: body + description: Pet object that needs to be added to the store + required: false + schema: + $ref: "#/definitions/Pet" responses: - 400: - description: Invalid ID supplied - 404: - description: Pet not found - 405: + "405": description: Validation exception + "404": + description: Pet not found + "400": + description: Invalid ID supplied security: - - petstore_auth: - - write:pets - - read:pets - /pet/findByStatus: + - petstore_auth: + - write_pets + - read_pets + /pets/findByStatus: get: tags: - - pet + - pet 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 produces: - - application/xml - - application/json + - application/json + - application/xml parameters: - - name: status - in: query - description: Status values that need to be considered for filter - required: true - type: array - items: - type: string - enum: - - available - - pending - - sold - default: available - collectionFormat: multi + - in: query + name: status + description: Status values that need to be considered for filter + required: false + type: array + items: + type: string + collectionFormat: multi responses: - 200: + "200": description: successful operation schema: type: array items: - $ref: '#/definitions/Pet' - 400: + $ref: "#/definitions/Pet" + "400": description: Invalid status value security: - - petstore_auth: - - write:pets - - read:pets - /pet/findByTags: + - petstore_auth: + - write_pets + - read_pets + /pets/findByTags: get: tags: - - pet + - pet summary: Finds Pets by tags - description: | - Muliple tags can be provided with comma separated strings. Use - tag1, tag2, tag3 for testing. + description: Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. operationId: findPetsByTags produces: - - application/xml - - application/json + - application/json + - application/xml parameters: - - name: tags - in: query - description: Tags to filter by - required: true - type: array - items: - type: string - collectionFormat: multi + - in: query + name: tags + description: Tags to filter by + required: false + type: array + items: + type: string + collectionFormat: multi responses: - 200: + "200": description: successful operation schema: type: array items: - $ref: '#/definitions/Pet' - 400: + $ref: "#/definitions/Pet" + "400": description: Invalid tag value security: - - petstore_auth: - - write:pets - - read:pets - deprecated: true - /pet/{petId}: + - petstore_auth: + - write_pets + - read_pets + /pets/{petId}: get: tags: - - pet + - pet 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 produces: - - application/xml - - application/json + - application/json + - application/xml parameters: - - name: petId - in: path - description: ID of pet to return - required: true - type: integer - format: int64 + - in: path + name: petId + description: ID of pet that needs to be fetched + required: true + type: integer + format: int64 responses: - 200: + "404": + description: Pet not found + "200": description: successful operation schema: - $ref: '#/definitions/Pet' - 400: + $ref: "#/definitions/Pet" + "400": description: Invalid ID supplied - 404: - description: Pet not found security: - - api_key: [] + - api_key: [] + - petstore_auth: + - write_pets + - read_pets post: tags: - - pet + - pet summary: Updates a pet in the store with form data - description: + description: "" operationId: updatePetWithForm consumes: - - application/x-www-form-urlencoded + - application/x-www-form-urlencoded produces: - - application/xml - - application/json + - application/json + - application/xml parameters: - - name: petId - in: path - description: ID of pet that needs to be updated - required: true - type: integer - format: int64 - - name: name - in: formData - description: Updated name of the pet - required: false - type: string - - name: status - in: formData - description: Updated status of the pet - required: false - type: string + - in: path + name: petId + description: ID of pet that needs to be updated + required: true + type: string + - in: formData + name: name + description: Updated name of the pet + required: true + type: string + - in: formData + name: status + description: Updated status of the pet + required: true + type: string responses: - 405: + "405": description: Invalid input security: - - petstore_auth: - - write:pets - - read:pets + - petstore_auth: + - write_pets + - read_pets delete: tags: - - pet + - pet summary: Deletes a pet + description: "" operationId: deletePet produces: - - application/xml - - application/json + - application/json + - application/xml parameters: - - name: api_key - in: header - required: false - type: string - - name: petId - in: path - description: Pet id to delete - required: true - type: integer - format: int64 + - in: header + name: api_key + description: "" + required: true + type: string + - in: path + name: petId + description: Pet id to delete + required: true + type: integer + format: int64 responses: - 400: - description: Invalid ID supplied - 404: - description: Pet not found + "400": + description: Invalid pet value security: - - petstore_auth: - - write:pets - - read:pets - /pet/{petId}/uploadImage: + - petstore_auth: + - write_pets + - read_pets + /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: - tags: - - store + - store summary: Place an order for a pet + description: "" operationId: placeOrder produces: - - application/xml - - application/json + - application/json + - application/xml parameters: - - in: body - name: body - description: order placed for purchasing the pet - required: true - schema: - $ref: '#/definitions/Order' + - in: body + name: body + description: order placed for purchasing the pet + required: false + schema: + $ref: "#/definitions/Order" responses: - 200: + "200": description: successful operation schema: - $ref: '#/definitions/Order' - 400: + $ref: "#/definitions/Order" + "400": description: Invalid Order - /store/order/{orderId}: + /stores/order/{orderId}: get: tags: - - store + - store summary: Find purchase order by ID - description: | - For valid response try integer IDs with value >= 1 and <= 10. - Other values will generated exceptions + description: For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions operationId: getOrderById produces: - - application/xml - - application/json + - application/json + - application/xml parameters: - - name: orderId - in: path - description: ID of pet that needs to be fetched - required: true - type: integer - maximum: 10.0 - minimum: 1.0 - format: int64 + - in: path + name: orderId + description: ID of pet that needs to be fetched + required: true + type: string responses: - 200: + "404": + description: Order not found + "200": description: successful operation schema: - $ref: '#/definitions/Order' - 400: + $ref: "#/definitions/Order" + "400": description: Invalid ID supplied - 404: - description: Order not found delete: tags: - - store + - store summary: Delete purchase order by ID - description: For valid response try integer IDs with positive integer value.\ - \ Negative or non-integer values will generate API errors + description: For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors operationId: deleteOrder produces: - - application/xml - - application/json + - application/json + - application/xml parameters: - - name: orderId - in: path - description: ID of the order that needs to be deleted - required: true - type: integer - minimum: 1.0 - format: int64 + - in: path + name: orderId + description: ID of the order that needs to be deleted + required: true + type: string responses: - 400: - description: Invalid ID supplied - 404: + "404": description: Order not found - /user: + "400": + description: Invalid ID supplied + /users: post: tags: - - user + - user summary: Create user description: This can only be done by the logged in user. operationId: createUser produces: - - application/xml - - application/json + - application/json + - application/xml parameters: - - in: body - name: body - description: Created user object - required: true - schema: - $ref: '#/definitions/User' + - in: body + name: body + description: Created user object + required: false + schema: + $ref: "#/definitions/User" responses: default: description: successful operation - /user/createWithArray: + /users/createWithArray: post: tags: - - user + - user summary: Creates list of users with given input array + description: "" operationId: createUsersWithArrayInput produces: - - application/xml - - application/json + - application/json + - application/xml parameters: - - in: body - name: body - description: List of user object - required: true - schema: - type: array - items: - $ref: '#/definitions/User' + - in: body + name: body + description: List of user object + required: false + schema: + type: array + items: + $ref: "#/definitions/User" responses: default: description: successful operation - /user/createWithList: + /users/createWithList: post: tags: - - user + - user summary: Creates list of users with given input array + description: "" operationId: createUsersWithListInput produces: - - application/xml - - application/json + - application/json + - application/xml parameters: - - in: body - name: body - description: List of user object - required: true - schema: - type: array - items: - $ref: '#/definitions/User' + - in: body + name: body + description: List of user object + required: false + schema: + type: array + items: + $ref: "#/definitions/User" responses: default: description: successful operation - /user/login: + /users/login: get: tags: - - user + - user summary: Logs user into the system + description: "" operationId: loginUser produces: - - application/xml - - application/json + - application/json + - application/xml parameters: - - name: username - in: query - description: The user name for login - required: true - type: string - - name: password - in: query - description: The password for login in clear text - required: true - type: string + - in: query + name: username + description: The user name for login + required: false + type: string + - in: query + name: password + description: The password for login in clear text + required: false + type: string responses: - 200: + "200": description: successful operation schema: type: string - headers: - 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: + "400": description: Invalid username/password supplied - /user/logout: + /users/logout: get: tags: - - user + - user summary: Logs out current logged in user session - description: + description: "" operationId: logoutUser produces: - - application/xml - - application/json - parameters: [] + - application/json + - application/xml responses: default: description: successful operation - /user/{username}: + /users/{username}: get: tags: - - user + - user summary: Get user by user name + description: "" operationId: getUserByName produces: - - application/xml - - application/json + - application/json + - application/xml parameters: - - name: username - in: path - description: The name that needs to be fetched. Use user1 for testing. - required: true - type: string + - in: path + name: username + description: The name that needs to be fetched. Use user1 for testing. + required: true + type: string responses: - 200: + "404": + description: User not found + "200": description: successful operation schema: - $ref: '#/definitions/User' - 400: + $ref: "#/definitions/User" + "400": description: Invalid username supplied - 404: - description: User not found put: tags: - - user + - user summary: Updated user description: This can only be done by the logged in user. operationId: updateUser produces: - - application/xml - - application/json + - application/json + - application/xml parameters: - - name: username - in: path - description: name that need to be updated - required: true - type: string - - in: body - name: body - description: Updated user object - required: true - schema: - $ref: '#/definitions/User' + - in: path + name: username + description: name that need to be deleted + required: true + type: string + - in: body + name: body + description: Updated user object + required: false + schema: + $ref: "#/definitions/User" responses: - 400: - description: Invalid user supplied - 404: + "404": description: User not found + "400": + description: Invalid user supplied delete: tags: - - user + - user summary: Delete user description: This can only be done by the logged in user. operationId: deleteUser produces: - - application/xml - - application/json + - application/json + - application/xml parameters: - - name: username - in: path - description: The name that needs to be deleted - required: true - type: string + - in: path + name: username + description: The name that needs to be deleted + required: true + type: string responses: - 400: - description: Invalid username supplied - 404: + "404": description: User not found + "400": + description: Invalid username supplied 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: type: apiKey name: api_key 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: - 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: type: object properties: @@ -624,8 +513,6 @@ definitions: type: integer format: int32 description: User Status - xml: - name: User Category: type: object properties: @@ -634,8 +521,31 @@ definitions: format: int64 name: type: string - xml: - name: Category + Pet: + type: object + required: + - name + - photoUrls + properties: + id: + type: integer + format: int64 + category: + $ref: "#/definitions/Category" + name: + type: string + example: doggie + photoUrls: + type: array + items: + type: string + tags: + type: array + items: + $ref: "#/definitions/Tag" + status: + type: string + description: pet status in the store Tag: type: object properties: @@ -644,55 +554,23 @@ definitions: format: int64 name: type: string - xml: - name: Tag - Pet: + Order: type: object - required: - - name - - photoUrls properties: id: type: integer format: int64 - category: - $ref: '#/definitions/Category' - name: - type: string - example: doggie - photoUrls: - type: array - xml: - name: photoUrl - wrapped: true - items: - type: string - tags: - type: array - xml: - name: tag - wrapped: true - items: - $ref: '#/definitions/Tag' - status: - type: string - description: pet status in the store - enum: - - available - - pending - - sold - xml: - name: Pet - ApiResponse: - type: object - properties: - code: + petId: + type: integer + format: int64 + quantity: type: integer format: int32 - type: + shipDate: type: string - message: + format: date-time + status: type: string -externalDocs: - description: Find out more about Swagger - url: http://swagger.io + description: Order Status + complete: + type: boolean \ No newline at end of file diff --git a/samples/server/petstore/sinatra/api/pet_api.rb b/samples/server/petstore/sinatra/api/pet_api.rb index 7ccad2056b9..3ca40f568d3 100644 --- a/samples/server/petstore/sinatra/api/pet_api.rb +++ b/samples/server/petstore/sinatra/api/pet_api.rb @@ -1,39 +1,12 @@ require 'json' -MyApp.add_route('PUT', '/v2/pet', { - "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', { +MyApp.add_route('POST', '/v2/pets', { "resourcePath" => "/Pet", "summary" => "Add a new pet to the store", "nickname" => "add_pet", "responseClass" => "void", - "endpoint" => "/pet", + "endpoint" => "/pets", "notes" => "", "parameters" => [ @@ -55,126 +28,12 @@ MyApp.add_route('POST', '/v2/pet', { end -MyApp.add_route('GET', '/v2/pet/findByStatus', { - "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}', { +MyApp.add_route('DELETE', '/v2/pets/{petId}', { "resourcePath" => "/Pet", "summary" => "Deletes a pet", "nickname" => "delete_pet", "responseClass" => "void", - "endpoint" => "/pet/{petId}", + "endpoint" => "/pets/{petId}", "notes" => "", "parameters" => [ @@ -203,25 +62,139 @@ MyApp.add_route('DELETE', '/v2/pet/{petId}', { end -MyApp.add_route('POST', '/v2/pet/{petId}/uploadImage', { +MyApp.add_route('GET', '/v2/pets/findByStatus', { "resourcePath" => "/Pet", - "summary" => "uploads an image", - "nickname" => "upload_file", - "responseClass" => "void", - "endpoint" => "/pet/{petId}/uploadImage", - "notes" => "", + "summary" => "Finds Pets by status", + "nickname" => "find_pets_by_status", + "responseClass" => "array[Pet]", + "endpoint" => "/pets/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" => "", + + }, + + + + + ]}) 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" => [ { "name" => "pet_id", - "description" => "ID of pet to update", + "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('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 cross_origin # the guts live here diff --git a/samples/server/petstore/sinatra/api/store_api.rb b/samples/server/petstore/sinatra/api/store_api.rb index 37938b304db..26ac567759b 100644 --- a/samples/server/petstore/sinatra/api/store_api.rb +++ b/samples/server/petstore/sinatra/api/store_api.rb @@ -1,44 +1,24 @@ require 'json' -MyApp.add_route('GET', '/v2/store/inventory', { +MyApp.add_route('DELETE', '/v2/stores/order/{orderId}', { "resourcePath" => "/Store", - "summary" => "Returns pet inventories by status", - "nickname" => "get_inventory", - "responseClass" => "map[string,int]", - "endpoint" => "/store/inventory", - "notes" => "Returns a map of status codes to quantities", + "summary" => "Delete purchase order by ID", + "nickname" => "delete_order", + "responseClass" => "void", + "endpoint" => "/stores/order/{orderId}", + "notes" => "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors", "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", - "description" => "order placed for purchasing the pet", - "dataType" => "Order", - "paramType" => "body", - } + "name" => "order_id", + "description" => "ID of the order that needs to be deleted", + "dataType" => "string", + "paramType" => "path", + }, + + ]}) do cross_origin @@ -48,12 +28,12 @@ MyApp.add_route('POST', '/v2/store/order', { end -MyApp.add_route('GET', '/v2/store/order/{orderId}', { +MyApp.add_route('GET', '/v2/stores/order/{orderId}', { "resourcePath" => "/Store", "summary" => "Find purchase order by ID", "nickname" => "get_order_by_id", "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", "parameters" => [ @@ -75,24 +55,24 @@ MyApp.add_route('GET', '/v2/store/order/{orderId}', { end -MyApp.add_route('DELETE', '/v2/store/order/{orderId}', { +MyApp.add_route('POST', '/v2/stores/order', { "resourcePath" => "/Store", - "summary" => "Delete purchase order by ID", - "nickname" => "delete_order", - "responseClass" => "void", - "endpoint" => "/store/order/{orderId}", - "notes" => "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors", + "summary" => "Place an order for a pet", + "nickname" => "place_order", + "responseClass" => "Order", + "endpoint" => "/stores/order", + "notes" => "", "parameters" => [ + + { - "name" => "order_id", - "description" => "ID of the order that needs to be deleted", - "dataType" => "string", - "paramType" => "path", - }, - - + "name" => "body", + "description" => "order placed for purchasing the pet", + "dataType" => "Order", + "paramType" => "body", + } ]}) do cross_origin diff --git a/samples/server/petstore/sinatra/api/user_api.rb b/samples/server/petstore/sinatra/api/user_api.rb index 7b890004891..aaa76430310 100644 --- a/samples/server/petstore/sinatra/api/user_api.rb +++ b/samples/server/petstore/sinatra/api/user_api.rb @@ -1,12 +1,12 @@ require 'json' -MyApp.add_route('POST', '/v2/user', { +MyApp.add_route('POST', '/v2/users', { "resourcePath" => "/User", "summary" => "Create user", "nickname" => "create_user", "responseClass" => "void", - "endpoint" => "/user", + "endpoint" => "/users", "notes" => "This can only be done by the logged in user.", "parameters" => [ @@ -28,12 +28,12 @@ MyApp.add_route('POST', '/v2/user', { end -MyApp.add_route('POST', '/v2/user/createWithArray', { +MyApp.add_route('POST', '/v2/users/createWithArray', { "resourcePath" => "/User", "summary" => "Creates list of users with given input array", "nickname" => "create_users_with_array_input", "responseClass" => "void", - "endpoint" => "/user/createWithArray", + "endpoint" => "/users/createWithArray", "notes" => "", "parameters" => [ @@ -55,12 +55,12 @@ MyApp.add_route('POST', '/v2/user/createWithArray', { end -MyApp.add_route('POST', '/v2/user/createWithList', { +MyApp.add_route('POST', '/v2/users/createWithList', { "resourcePath" => "/User", "summary" => "Creates list of users with given input array", "nickname" => "create_users_with_list_input", "responseClass" => "void", - "endpoint" => "/user/createWithList", + "endpoint" => "/users/createWithList", "notes" => "", "parameters" => [ @@ -82,12 +82,66 @@ MyApp.add_route('POST', '/v2/user/createWithList', { 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", "summary" => "Logs user into the system", "nickname" => "login_user", "responseClass" => "string", - "endpoint" => "/user/login", + "endpoint" => "/users/login", "notes" => "", "parameters" => [ @@ -122,12 +176,12 @@ MyApp.add_route('GET', '/v2/user/login', { end -MyApp.add_route('GET', '/v2/user/logout', { +MyApp.add_route('GET', '/v2/users/logout', { "resourcePath" => "/User", "summary" => "Logs out current logged in user session", "nickname" => "logout_user", "responseClass" => "void", - "endpoint" => "/user/logout", + "endpoint" => "/users/logout", "notes" => "", "parameters" => [ @@ -142,39 +196,12 @@ MyApp.add_route('GET', '/v2/user/logout', { end -MyApp.add_route('GET', '/v2/user/{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}', { +MyApp.add_route('PUT', '/v2/users/{username}', { "resourcePath" => "/User", "summary" => "Updated user", "nickname" => "update_user", "responseClass" => "void", - "endpoint" => "/user/{username}", + "endpoint" => "/users/{username}", "notes" => "This can only be done by the logged in user.", "parameters" => [ @@ -202,30 +229,3 @@ MyApp.add_route('PUT', '/v2/user/{username}', { {"message" => "yes, it worked"}.to_json 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 - diff --git a/samples/server/petstore/sinatra/lib/swaggering.rb b/samples/server/petstore/sinatra/lib/swaggering.rb index 1357bb19134..69cc74556ac 100644 --- a/samples/server/petstore/sinatra/lib/swaggering.rb +++ b/samples/server/petstore/sinatra/lib/swaggering.rb @@ -39,7 +39,7 @@ class Swaggering < Sinatra::Base def self.add_route(method, path, swag={}, opts={}, &block) #fullPath = swag["resourcePath"].to_s + @@configuration.format_specifier + path - fullPath = path.gsub(/{(.*)}/, ':\1') + fullPath = path.gsub(/{(.*?)}/, ':\1') accepted = case method.to_s.downcase when 'get' diff --git a/samples/server/petstore/sinatra/swagger.yaml b/samples/server/petstore/sinatra/swagger.yaml index 49a3405de09..4aa26a9539c 100644 --- a/samples/server/petstore/sinatra/swagger.yaml +++ b/samples/server/petstore/sinatra/swagger.yaml @@ -1,15 +1,14 @@ --- swagger: "2.0" info: - description: "This is a sample server Petstore server. You can find out more about\ - \ Swagger at http://swagger.io or on irc.freenode.net,\ - \ #swagger. For this sample, you can use the api key \"special-key\" to test\ - \ the authorization filters" + description: "This is a sample server Petstore server.\n\n[Learn about Swagger](http://swagger.io)\ + \ or join the IRC channel `#swagger` on irc.freenode.net.\n\nFor this sample,\ + \ you can use the api key `special-key` to test the authorization filters\n" version: "1.0.0" title: "Swagger Petstore" - termsOfService: "http://swagger.io/terms/" + termsOfService: "http://helloreverb.com/terms/" contact: - email: "apiteam@swagger.io" + name: "apiteam@swagger.io" license: name: "Apache 2.0" url: "http://www.apache.org/licenses/LICENSE-2.0.html" @@ -18,7 +17,7 @@ basePath: "/v2" schemes: - "http" paths: - /pet: + /pets: post: tags: - "pet" @@ -43,8 +42,8 @@ paths: description: "Invalid input" security: - petstore_auth: - - "write:pets" - - "read:pets" + - "write_pets" + - "read_pets" put: tags: - "pet" @@ -73,9 +72,9 @@ paths: description: "Validation exception" security: - petstore_auth: - - "write:pets" - - "read:pets" - /pet/findByStatus: + - "write_pets" + - "read_pets" + /pets/findByStatus: get: tags: - "pet" @@ -94,7 +93,6 @@ paths: items: type: "string" collectionFormat: "multi" - default: "available" responses: 200: description: "successful operation" @@ -106,9 +104,9 @@ paths: description: "Invalid status value" security: - petstore_auth: - - "write:pets" - - "read:pets" - /pet/findByTags: + - "write_pets" + - "read_pets" + /pets/findByTags: get: tags: - "pet" @@ -139,9 +137,9 @@ paths: description: "Invalid tag value" security: - petstore_auth: - - "write:pets" - - "read:pets" - /pet/{petId}: + - "write_pets" + - "read_pets" + /pets/{petId}: get: tags: - "pet" @@ -171,8 +169,8 @@ paths: security: - api_key: [] - petstore_auth: - - "write:pets" - - "read:pets" + - "write_pets" + - "read_pets" post: tags: - "pet" @@ -193,20 +191,20 @@ paths: - name: "name" in: "formData" description: "Updated name of the pet" - required: false + required: true type: "string" - name: "status" in: "formData" description: "Updated status of the pet" - required: false + required: true type: "string" responses: 405: description: "Invalid input" security: - petstore_auth: - - "write:pets" - - "read:pets" + - "write_pets" + - "read_pets" delete: tags: - "pet" @@ -220,7 +218,7 @@ paths: - name: "api_key" in: "header" description: "" - required: false + required: true type: "string" - name: "petId" in: "path" @@ -233,66 +231,9 @@ paths: description: "Invalid pet value" security: - petstore_auth: - - "write:pets" - - "read:pets" - /pet/{petId}/uploadImage: - 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: + - "write_pets" + - "read_pets" + /stores/order: post: tags: - "store" @@ -316,7 +257,7 @@ paths: $ref: "#/definitions/Order" 400: description: "Invalid Order" - /store/order/{orderId}: + /stores/order/{orderId}: get: tags: - "store" @@ -363,7 +304,7 @@ paths: description: "Invalid ID supplied" 404: description: "Order not found" - /user: + /users: post: tags: - "user" @@ -383,7 +324,7 @@ paths: responses: default: description: "successful operation" - /user/createWithArray: + /users/createWithArray: post: tags: - "user" @@ -405,7 +346,7 @@ paths: responses: default: description: "successful operation" - /user/createWithList: + /users/createWithList: post: tags: - "user" @@ -427,7 +368,7 @@ paths: responses: default: description: "successful operation" - /user/login: + /users/login: get: tags: - "user" @@ -455,7 +396,7 @@ paths: type: "string" 400: description: "Invalid username/password supplied" - /user/logout: + /users/logout: get: tags: - "user" @@ -469,7 +410,7 @@ paths: responses: default: description: "successful operation" - /user/{username}: + /users/{username}: get: tags: - "user" @@ -482,7 +423,7 @@ paths: parameters: - name: "username" 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 type: "string" responses: @@ -490,16 +431,6 @@ paths: description: "successful operation" schema: $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: description: "Invalid username supplied" 404: @@ -560,10 +491,11 @@ securityDefinitions: authorizationUrl: "http://petstore.swagger.io/api/oauth/dialog" flow: "implicit" scopes: - write:pets: "modify pets in your account" - read:pets: "read your pets" + write_pets: "modify pets in your account" + read_pets: "read your pets" definitions: User: + type: "object" properties: id: type: "integer" @@ -584,18 +516,16 @@ definitions: type: "integer" format: "int32" description: "User Status" - xml: - name: "User" Category: + type: "object" properties: id: type: "integer" format: "int64" name: type: "string" - xml: - name: "Category" Pet: + type: "object" required: - "name" - "photoUrls" @@ -610,37 +540,25 @@ definitions: example: "doggie" photoUrls: type: "array" - xml: - name: "photoUrl" - wrapped: true items: type: "string" tags: type: "array" - xml: - name: "tag" - wrapped: true items: $ref: "#/definitions/Tag" status: type: "string" description: "pet status in the store" - enum: - - "available" - - "pending" - - "sold" - xml: - name: "Pet" Tag: + type: "object" properties: id: type: "integer" format: "int64" name: type: "string" - xml: - name: "Tag" Order: + type: "object" properties: id: type: "integer" @@ -657,11 +575,5 @@ definitions: status: type: "string" description: "Order Status" - enum: - - "placed" - - "approved" - - "delivered" complete: type: "boolean" - xml: - name: "Order"