Git Product home page Git Product logo

swagger-petstore's Introduction

Swagger Petstore Sample

Overview

This is the pet store sample hosted at https://petstore3.swagger.io. For other versions, check the branches. We welcome suggestion both the code and the API design. To make changes to the design itself, take a look at https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml.

This is a java project to build a stand-alone server which implements the OpenAPI 3 Spec. You can find out more about both the spec and the framework at http://swagger.io.

This sample is based on swagger-inflector, and provides an example of swagger / OpenAPI 3 petstore.

To run (with Maven)

To run the server, run this task:

mvn package jetty:run

This will start Jetty embedded on port 8080.

To run (via Docker)

Expose port 8080 from the image and access petstore via the exposed port. You can then add and delete pets as you see fit.

Example:

docker build -t swaggerapi/petstore3:unstable .
docker pull swaggerapi/petstore3:unstable
docker run  --name swaggerapi-petstore3 -d -p 8080:8080 swaggerapi/petstore3:unstable

Testing the server

Once started, you can navigate to http://localhost:8080/api/v3/openapi.json to view the Swagger Resource Listing. This tells you that the server is up and ready to demonstrate Swagger.

Using the UI

There is an HTML5-based API tool bundled in this sample--you can view it it at http://localhost:8080. This lets you inspect the API using an interactive UI. You can access the source of this code from here

swagger-petstore's People

Contributors

char0n avatar frantuma avatar hkosova avatar mend-for-github-com[bot] avatar micryc avatar mjac avatar perrinjerome avatar ponelat avatar tim-lai avatar timo-a avatar webron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swagger-petstore's Issues

petstore 1.0.18 has wrong scheme!

pet.id.type should be integer

"Pet": {
                "required": [
                    "name",
                    "photoUrls"
                ],
                "type": "object",
                "properties": {
                    "id": {
                        "required": [
                            "name",
                            "photoUrls"
                        ],
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "integer",
                                "format": "int64",
                                "example": 10
                            },
                            "name": {
                                "type": "string",
                                "example": "doggie"
                            },
                            "category": {
                                "$ref": "#/components/schemas/Category"
                            },
                            "photoUrls": {
                                "type": "array",
                                "xml": {
                                    "wrapped": true
                                },
                                "items": {
                                    "type": "string",
                                    "xml": {
                                        "name": "photoUrl"
                                    }
                                }
                            },
                            "tags": {
                                "type": "array",
                                "xml": {
                                    "wrapped": true
                                },
                                "items": {
                                    "$ref": "#/components/schemas/Tag"
                                }
                            },
                            "status": {
                                "type": "string",
                                "description": "pet status in the store",
                                "enum": [
                                    "available",
                                    "pending",
                                    "sold"
                                ]
                            }
                        },
                        "xml": {
                            "name": "pet"
                        }
                    },
                    "name": {
                        "required": [
                            "name",
                            "photoUrls"
                        ],
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "integer",
                                "format": "int64",
                                "example": 10
                            },
                            "name": {
                                "type": "string",
                                "example": "doggie"
                            },
                            "category": {
                                "$ref": "#/components/schemas/Category"
                            },
                            "photoUrls": {
                                "type": "array",
                                "xml": {
                                    "wrapped": true
                                },
                                "items": {
                                    "type": "string",
                                    "xml": {
                                        "name": "photoUrl"
                                    }
                                }
                            },
                            "tags": {
                                "type": "array",
                                "xml": {
                                    "wrapped": true
                                },
                                "items": {
                                    "$ref": "#/components/schemas/Tag"
                                }
                            },
                            "status": {
                                "type": "string",
                                "description": "pet status in the store",
                                "enum": [
                                    "available",
                                    "pending",
                                    "sold"
                                ]
                            }
                        },
                        "xml": {
                            "name": "pet"
                        }
                    },
                    "category": {
                        "required": [
                            "name",
                            "photoUrls"
                        ],
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "integer",
                                "format": "int64",
                                "example": 10
                            },
                            "name": {
                                "type": "string",
                                "example": "doggie"
                            },
                            "category": {
                                "$ref": "#/components/schemas/Category"
                            },
                            "photoUrls": {
                                "type": "array",
                                "xml": {
                                    "wrapped": true
                                },
                                "items": {
                                    "type": "string",
                                    "xml": {
                                        "name": "photoUrl"
                                    }
                                }
                            },
                            "tags": {
                                "type": "array",
                                "xml": {
                                    "wrapped": true
                                },
                                "items": {
                                    "$ref": "#/components/schemas/Tag"
                                }
                            },
                            "status": {
                                "type": "string",
                                "description": "pet status in the store",
                                "enum": [
                                    "available",
                                    "pending",
                                    "sold"
                                ]
                            }
                        },
                        "xml": {
                            "name": "pet"
                        }
                    },
                    "photoUrls": {
                        "required": [
                            "name",
                            "photoUrls"
                        ],
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "integer",
                                "format": "int64",
                                "example": 10
                            },
                            "name": {
                                "type": "string",
                                "example": "doggie"
                            },
                            "category": {
                                "$ref": "#/components/schemas/Category"
                            },
                            "photoUrls": {
                                "type": "array",
                                "xml": {
                                    "wrapped": true
                                },
                                "items": {
                                    "type": "string",
                                    "xml": {
                                        "name": "photoUrl"
                                    }
                                }
                            },
                            "tags": {
                                "type": "array",
                                "xml": {
                                    "wrapped": true
                                },
                                "items": {
                                    "$ref": "#/components/schemas/Tag"
                                }
                            },
                            "status": {
                                "type": "string",
                                "description": "pet status in the store",
                                "enum": [
                                    "available",
                                    "pending",
                                    "sold"
                                ]
                            }
                        },
                        "xml": {
                            "name": "pet"
                        }
                    },
                    "tags": {
                        "required": [
                            "name",
                            "photoUrls"
                        ],
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "integer",
                                "format": "int64",
                                "example": 10
                            },
                            "name": {
                                "type": "string",
                                "example": "doggie"
                            },
                            "category": {
                                "$ref": "#/components/schemas/Category"
                            },
                            "photoUrls": {
                                "type": "array",
                                "xml": {
                                    "wrapped": true
                                },
                                "items": {
                                    "type": "string",
                                    "xml": {
                                        "name": "photoUrl"
                                    }
                                }
                            },
                            "tags": {
                                "type": "array",
                                "xml": {
                                    "wrapped": true
                                },
                                "items": {
                                    "$ref": "#/components/schemas/Tag"
                                }
                            },
                            "status": {
                                "type": "string",
                                "description": "pet status in the store",
                                "enum": [
                                    "available",
                                    "pending",
                                    "sold"
                                ]
                            }
                        },
                        "xml": {
                            "name": "pet"
                        }
                    },
                    "status": {
                        "required": [
                            "name",
                            "photoUrls"
                        ],
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "integer",
                                "format": "int64",
                                "example": 10
                            },
                            "name": {
                                "type": "string",
                                "example": "doggie"
                            },
                            "category": {
                                "$ref": "#/components/schemas/Category"
                            },
                            "photoUrls": {
                                "type": "array",
                                "xml": {
                                    "wrapped": true
                                },
                                "items": {
                                    "type": "string",
                                    "xml": {
                                        "name": "photoUrl"
                                    }
                                }
                            },
                            "tags": {
                                "type": "array",
                                "xml": {
                                    "wrapped": true
                                },
                                "items": {
                                    "$ref": "#/components/schemas/Tag"
                                }
                            },
                            "status": {
                                "type": "string",
                                "description": "pet status in the store",
                                "enum": [
                                    "available",
                                    "pending",
                                    "sold"
                                ]
                            }
                        },
                        "xml": {
                            "name": "pet"
                        }
                    }
                },
                "xml": {
                    "name": "pet"
                }
            },

api/v3 Petstore /pet endpoint throws 500 error on POST request

https://petstore3.swagger.io/api/v3/openapi.json

Even when I execute the example request from Swagger UI the response is 500.

Here is the valid response body as per the schema

{
  "id": 10,
  "name": "doggie",
  "category": {
    "id": 1,
    "name": "Dogs"
  },
  "photoUrls": [
    "string"
  ],
  "tags": [
    {
      "id": 0,
      "name": "string"
    }
  ],
  "status": "available"
}

And this is the response

 <code>500</code>
 <message>There was an error processing your request. It has been logged (ID: 8e3eae56f355c584)</message>

API improvements meta issue

I've opened a relatively large number of PRs, so I though I'd create this issue for feedback that applies across all of them (or so you can tell me to bugger off).

First off, I'm glad that there is an example API for OpenAPI. It's a good to have a reference for how to use the format, and with OpenAPI's popularity provides a good way for people to implement the same API in different languages/stacks.

I was initially intending to implement the API myself but ran into a number of things that made it unclear how to proceed or that just didn't make sense. I've opened several issues to address a number of those issues, as well as some that reflect a preference that I think is somewhat close to a best practice.

Issues are as below

  • #46 - remove unused models
  • #47 - make query parameter format reflect the description
  • #48 - don't send ids on requests, don't send password in response(!)
  • #49 - put path parameters at the path level
  • #50 - provide id for updating the pet in the path instead of body
  • #51 - put partial pet update in body instead of query
  • #52 - get /pets
  • #53 - kill category and tag objects
  • #54 - add auth as described
  • #55 - use plural path segments
  • #56 - don't return 405
  • #58 - don't use GET for login(!)

Calls to /store/inventory return a 500 code after creating an order with null status

Seams that on local after creating an order with null in the status results in the inventory not working anymore and always returning a 500 code with the server logging:
8:56.287 [qtp1407036358-30] ERROR i.s.o.i.utils.DefaultExceptionMapper - There was an error processing your request. It has been logged (ID: 79674d24bfbafb00) com.fasterxml.jackson.databind.JsonMappingException: Null key for a Map not allowed in JSON (use a converting NullKeySerializer?) (through reference chain: java.util.HashMap["null"])

from the behavior of the online version and the server logs on local that don't seam to notice that the order status is null this issue might be also present on petstore3.swagger.io and not just localhost :)

to reproduce simply get the inventory like so:
curl -X GET "http://localhost:8080/api/v3/store/inventory" -H "accept: application/json"

if it returns a 500 you might have already triggered the issue and need to restart the server and try again BUT
if it works create the following order like so:

curl -X POST "http://localhost:8080/api/v3/store/order" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"id\":10,\"petId\":198772,\"quantity\":7,\"shipDate\":\"2021-02-24T08:34:46.244Z\",\"status\":null,\"complete\":true}"

OR

curl -X POST "http://localhost:8080/api/v3/store/order" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"status\":null}"

and try to get the inventory again.

this consistently returns 500 after that faithful order.

validation of required input parameters

In petstore api, the photoUrls property of the Pet definition is a required property.

When I tried to register a new pet using curl, if I set the photoUrls to null, the pet is registered in the store.

curl -X 'POST'
'https://petstore.swagger.io/v2/pet'
-H 'accept: application/json'
-H 'Content-Type: application/json'
-d '{
"id": 123456789987,
"category": {
"id": 0,
"name": "string"
},
"name": "doggie",
"photoUrls": null,
"tags": [
{
"id": 0,
"name": "TheTag"
}
],
"status": "available"
}'

When I tried to look at this pet using the path /pet

curl -X 'GET'
'https://petstore.swagger.io/v2/pet/123456789987'
-H 'accept: application/json'

{"id":123456789987,"category":{"id":0,"name":"string"},"name":"doggie","tags":[{"id":0,"name":"TheTag"}],"status":"available"}

The answer does not contain the required photoUrls property (and some of the sdk generated with the swagger generator that check that this property is set (python) produce an error.)

Thanks

Local docker build throws 500 server errors

When building the docker image myself the server throws HTTP 500 errors when calling a request with the following error:
Implementation of JAXB-API has not been found on module path or classpath.

The following dependencies are missing:

<!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.0-b170201.1204</version>
</dependency>

<!-- https://mvnrepository.com/artifact/javax.activation/activation -->
<dependency>
    <groupId>javax.activation</groupId>
    <artifactId>activation</artifactId>
    <version>1.1</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.glassfish.jaxb/jaxb-runtime -->
<dependency>
    <groupId>org.glassfish.jaxb</groupId>
    <artifactId>jaxb-runtime</artifactId>
    <version>2.3.0</version>
</dependency>

Also I got it only running with Java 8.
Then it's working as expected.

Multiple 500 Internal Server Error caused by muted input data

  1. "quantity" parameter = 0 causing Internal Server Error.

Request:

"url": "http://localhost/v2/store/order",
"method": "post",
"data": { "id": 0, "petId": 444985,"quantity": 0, "shipDate": "JLRIECHB7EQ3DQCMR","status": "delivered", "complete": "false"},

Response:

"code":500,"type":"unknown","message":"something bad happened"

  1. Create/update user information /pet information causing 500 internal server error.

Example on user directory:

Request:

"url": "http://localhost:80/v2/user/doggie",
"method": "put" or "post",
"data": {"id": 977982,"username": "ZYP0726B3PHUB7WL5Y2KTBMVC25W8S2UQSHLKVCWC11P6CSCCZDH6BOYYTJGPOYSTC1J8HI3GX3383P9AU","firstName": "7NFL8R1UV45YPRTD7JHVF7Y1U93UY76GIXK3T70Z2W57FGP4KXYK9E4GSCDE3FMATFV6NT45RIU484AC8V14OMIBFLBV4ZMK", "lastName": "ZYP0726B3PHUB7WL5Y2KTBMVC25W8S2UQSHLKVCWC11P6CSCCZDH6BOYYTJGPOYSTC1J8HI3GX3383P9AU",
"email": "98O89VZGRDAVY6EERB6FRR5N", "password": "2021-02-26T15:08:16.049+0000", "phone": "MNA1YJ8F5APIV0VSZCOIN1P","userStatus": "delivered" },

Response:

"code":500,"type":"unknown","message":"something bad happened"

  1. large quantity causing internal server error, example:

"url": "http://localhost:80/v2/store/order",
"method": "post",
"data": {"id": 428388,"petId": 0,"quantity": 898379, "shipDate": "unknown", "status": "placed","complete": "true" },

Response:

"code":500,"type":"unknown","message":"something bad happened"

  1. createUsersWithArrayInput request with false date format causing internal server error. Example:

"url": "http://localhost:80/v2/user/createWithArray",
"method": "post",
"data": ["SDD7JG30RCE9ZNKODPQ94X0QTR0W2EQ52VCTQF3ENY2GLFUZ2HXH"],

Response:

"code":500,"type":"unknown","message":"something bad happened"

Add a security policy

Hey there!

I belong to an open source security research community, and a member (@ShellInjector) has found an issue, but doesn’t know the best way to disclose it.

If not a hassle, might you kindly add a SECURITY.md file with an email, or another contact method? GitHub recommends this best practice to ensure security issues are responsibly disclosed, and it would serve as a simple instruction for security researchers in the future.

Thank you for your consideration, and I look forward to hearing from you!

(cc @huntr-helper)

swagger-jaxrs2 and swagger-parser version gives a not found error

io.swagger.core.v3 swagger-jaxrs2 ${swagger-core-version}
    <dependency>
        <groupId>io.swagger.parser.v3</groupId>
        <artifactId>swagger-parser</artifactId>
        <version>${swagger-parser-version}</version>
    </dependency>

Versions values:
swagger-parser-version = 2.0.19-SNAPSHOT
swagger-core-version = 2.1.2-SNAPSHOT

Only works when removing the postfix '-SNAPSHOT'

Some 500 server error

I got some 500 server error when I test API.Here are some examples and my analysis of the causes of the errors.

1.Parameter type does not match

500 error is triggered when I pass in a parameter that does not match the API format document.After analysis, I think it's a problem with the email, phone and passwrod parameters

curl \
  --request POST \
  --url 'http://localhost:8080/api/v3/user\
  --header 'Content-Type: application/json' \
  --data '{"email":true}' \
  --location \
  --max-redirs 32
curl \
  --request POST \
  --url 'http://localhost:8080/api/v3/user\
  --header 'Content-Type: application/json' \
  --data '{"passwrod":true}' \
  --location \
  --max-redirs 32
curl \
  --request POST \
  --url 'http://localhost:8080/api/v3/user\
  --header 'Content-Type: application/json' \
  --data '{"phone":true}' \
  --location \
  --max-redirs 32

Update unexist pet_id

This issue is triggered when a non-existent pet_id is updated using uploadImage

curl \
  --request POST \
  --url 'http://localhost:8080/api/v3/pet/1232/uploadImage\
  --header 'Content-Type: application/json' \
  --location \
  --max-redirs 32

Get , Update or Delete unexist username

This issue is triggered when a non-existent username is updated

curl \
  --request POST \
  --url 'http://localhost:8080/api/v3/user/xxxx\
  --header 'Content-Type: application/json' \
  --location \
  --max-redirs 32
curl \
  --request GET \
  --url 'http://localhost:8080/api/v3/user/xxxx\
  --header 'Content-Type: application/json' \
  --location \
  --max-redirs 32
curl \
  --request Delete \
  --url 'http://localhost:8080/api/v3/user/xxxx\
  --header 'Content-Type: application/json' \
  --location \
  --max-redirs 32

The description should be updated for /pet/findByTags and /pet/findByStatus:

for both Swagger 2.0 and OAS3 API definition, the description text should reflect desired spec behavior.

/pet/findByTags

Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.

UI behavior: for each desired tag, user should click on "Add item", then input tag

/pet/findByStatus:

Multiple status values can be provided with comma separated strings.

UI behavior: user should shift+click each status value from the dropdown select options

Multiple operations return values that are not described correctly by the OpenAPI document

Delete pet operation returns 200 response

Delete pet operation returns 200 response, but the spec only describes a 400 for invalid ID.

Example:

curl -X 'DELETE' \
  'https://petstore3.swagger.io/api/v3/pet/10' \
  -H 'accept: */*' \
  -H 'api_key: qqqq'

Returns:

< HTTP/2 200
< date: Fri, 22 Dec 2023 12:30:11 GMT
< content-type: application/json
< content-length: 11
< access-control-allow-origin: *
< access-control-allow-methods: GET, POST, DELETE, PUT
< access-control-allow-headers: Content-Type, api_key, Authorization
< access-control-expose-headers: Content-Disposition
< server: Jetty(9.4.9.v20180320)
<
* Connection #0 to host petstore3.swagger.io left intact
Pet deleted%

CleanShot 2023-12-22 at 14 22 07@2x

This is addressed in #109

Update pet with form returns a 200 response with a Pet object

The Pet object returned by updatePetWithForm is not described in the spec.

Example:

curl -X 'POST' --verbose \
  'https://petstore3.swagger.io/api/v3/pet/10?name=lizard&status=available' \
  -H 'accept: */*' \
  -d ''

Response:

< HTTP/2 200
< date: Fri, 22 Dec 2023 12:31:22 GMT
< content-type: application/json
< content-length: 137
< access-control-allow-origin: *
< access-control-allow-methods: GET, POST, DELETE, PUT
< access-control-allow-headers: Content-Type, api_key, Authorization
< access-control-expose-headers: Content-Disposition
< server: Jetty(9.4.9.v20180320)
<
* Connection #0 to host petstore3.swagger.io left intact
{"id":10,"category":{"id":1,"name":"Dogs"},"name":"lizard","photoUrls":["string"],"tags":[{"id":0,"name":"string"}],"status":"available"}%

CleanShot 2023-12-22 at 14 25 00@2x

trying to get swagger.json

when I try the latest code from master it is not generating swagger json so I went in tags and checkout swagger-petstore-swagger-petstore-v2-1.0.6 when I run it with mvn package jetty:run it works in port 8002 and when I request the page it give error below

image

how can I fix it ?

I am just trying to reach swagger json and its responses. for my project https://github.com/ozkanpakdil/swaggerific. I was using https://petstore.swagger.io/ but sometimes it starts responding empty arrays , I just need some data.

Docker Hub Setup Instructions & `SWAGGER_HOST` Variable

Hi 👋

I found a small Typo in the dockerhub documentation.

The documentation on docker hub (https://hub.docker.com/r/swaggerapi/petstore) says to start the container like this:

docker run -d -e SWAGGER_HOST=http://petstore.swagger.io \
  -e SWAGGER_BASE_PATH=/v2 -p 80:8080 swaggerapi/swagger-petstore

But the docker repo ist called swaggerapi/petstore not swaggerapi/swagger-petstore so the command will fail.

The correct command should be:

docker run -d -e SWAGGER_HOST=http://petstore.swagger.io \
  -e SWAGGER_BASE_PATH=/v2 -p 80:8080 swaggerapi/petstore

On a related note, the SWAGGER_HOST doesn't appear to be working correctly. When starting the container like described above the swagger ui still tries to fetch the swagger.json from http://localhost:8080/v2/swagger.json.

How to split Path Item Object into seperate yaml file ?

As a real-world project gose on, the number of paths grows, and the single yaml file becomes bigger, which lead to a slow loading when the swagger-ui js is trying to load a full yaml file.

I'd like to known how to spilt Path Item Object into seperate yaml files, but also keeps the auto-complete suggestion provided by any IDE, is there any official suggestions / guides / examples ?

  • IDEA uses schema store's open api schema to provide auto-complete suggestion.

Petstore API as REST API?

Wouldn't it be a good idea to design the API as a REST API? I'd like to show this sample in REST trainings, but unfortunately, it does not fit the guidelines.

Main points are

  • URLs:
    • pets instead of pet, users instead of user
    • findByStatus and findByTags as parameters of GET /pets
    • image upload with PUT /pets/{petId}/image
    • Login/Logout (if done via the API) by using POST

(Wouldn't have any problem to provide a merge request, but maybe it is a conscious decision to NOT fit REST guidelines?)

create pet shows 500 error when I am running the process locally

Hi, I'm running the process localy on http://localhost:8080/api/v3/openapi.json but when i want to create a new pet in the store, the response shows:

{ "code": 500, "message": "There was an error processing your request. It has been logged (ID: cc7b40b0becf48c4)" }

My request is:

{ "id": 0, "name": "Nalita", "category": { "id": 1, "name": "Dogs" }, "photoUrls": [ "https://cdn.pixabay.com/photo/2017/09/25/13/12/dog-2785074__340.jpg" ], "tags": [ { "id": 0, "name": "DogoArgentino" } ], "status": "available" }

Here is a sample image in postman:

image

pd: for the create user method, happens the same

Regards

IP address

Hi,

how or where do I change the IP address from 0.0.0.0 to 10.x.x.x to run the app from a VM?

Thanks,
A

Error starting server

I downloaded the master branch of this project, and entered the command

mvn package jetty:run

It downloaded dependencies, compiled the source, and tried to run the maven war plugin, which resulted in the following. Is there something obvious that I'm doing wrong? Thank you

com.google.inject.ProvisionException: Unable to provision, see the following errors:

  1. Error injecting constructor, java.lang.ExceptionInInitializerError: Cannot access defaults field of Properties
    at org.apache.maven.plugin.war.WarMojo.(Unknown Source)
    while locating org.apache.maven.plugin.war.WarMojo

1 error
at com.google.inject.internal.InternalProvisionException.toProvisionException (InternalProvisionException.java:226)
at com.google.inject.internal.InjectorImpl$1.get (InjectorImpl.java:1053)
at com.google.inject.internal.InjectorImpl.getInstance (InjectorImpl.java:1086)
at org.eclipse.sisu.space.AbstractDeferredClass.get (AbstractDeferredClass.java:48)
at com.google.inject.internal.ProviderInternalFactory.provision (ProviderInternalFactory.java:85)
at com.google.inject.internal.InternalFactoryToInitializableAdapter.provision (InternalFactoryToInitializableAdapter.java:57)
at com.google.inject.internal.ProviderInternalFactory$1.call (ProviderInternalFactory.java:66)
at com.google.inject.internal.ProvisionListenerStackCallback$Provision.provision (ProvisionListenerStackCallback.java:112)
at com.google.inject.internal.ProvisionListenerStackCallback$Provision.provision (ProvisionListenerStackCallback.java:127)
at com.google.inject.internal.ProvisionListenerStackCallback.provision (ProvisionListenerStackCallback.java:66)
at com.google.inject.internal.ProviderInternalFactory.circularGet (ProviderInternalFactory.java:61)
at com.google.inject.internal.InternalFactoryToInitializableAdapter.get (InternalFactoryToInitializableAdapter.java:47)
at com.google.inject.internal.InjectorImpl$1.get (InjectorImpl.java:1050)
at org.eclipse.sisu.inject.Guice4$1.get (Guice4.java:162)
at org.eclipse.sisu.inject.LazyBeanEntry.getValue (LazyBeanEntry.java:81)
at org.eclipse.sisu.plexus.LazyPlexusBean.getValue (LazyPlexusBean.java:51)
at org.codehaus.plexus.DefaultPlexusContainer.lookup (DefaultPlexusContainer.java:263)
at org.codehaus.plexus.DefaultPlexusContainer.lookup (DefaultPlexusContainer.java:255)
at org.apache.maven.plugin.internal.DefaultMavenPluginManager.getConfiguredMojo (DefaultMavenPluginManager.java:520)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:124)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:78)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:567)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: java.lang.ExceptionInInitializerError: Cannot access defaults field of Properties
at com.thoughtworks.xstream.converters.collections.PropertiesConverter. (PropertiesConverter.java:46)
at com.thoughtworks.xstream.XStream.setupConverters (XStream.java:647)
at com.thoughtworks.xstream.XStream. (XStream.java:445)
at com.thoughtworks.xstream.XStream. (XStream.java:385)
at com.thoughtworks.xstream.XStream. (XStream.java:342)
at org.apache.maven.plugin.war.util.WebappStructureSerializer. (WebappStructureSerializer.java:47)
at org.apache.maven.plugin.war.AbstractWarMojo. (AbstractWarMojo.java:316)
at org.apache.maven.plugin.war.WarMojo. (WarMojo.java:49)
at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0 (Native Method)
at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance (NativeConstructorAccessorImpl.java:78)
at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance (DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstanceWithCaller (Constructor.java:499)
at java.lang.reflect.Constructor.newInstance (Constructor.java:480)
at com.google.inject.internal.DefaultConstructionProxyFactory$ReflectiveProxy.newInstance (DefaultConstructionProxyFactory.java:126)
at com.google.inject.internal.ConstructorInjector.provision (ConstructorInjector.java:114)
at com.google.inject.internal.ConstructorInjector.access$000 (ConstructorInjector.java:32)
at com.google.inject.internal.ConstructorInjector$1.call (ConstructorInjector.java:98)
at com.google.inject.internal.ProvisionListenerStackCallback$Provision.provision (ProvisionListenerStackCallback.java:112)
at com.google.inject.internal.ProvisionListenerStackCallback$Provision.provision (ProvisionListenerStackCallback.java:127)
at com.google.inject.internal.ProvisionListenerStackCallback.provision (ProvisionListenerStackCallback.java:66)
at com.google.inject.internal.ConstructorInjector.construct (ConstructorInjector.java:93)
at com.google.inject.internal.ConstructorBindingImpl$Factory.get (ConstructorBindingImpl.java:306)
at com.google.inject.internal.InjectorImpl$1.get (InjectorImpl.java:1050)
at com.google.inject.internal.InjectorImpl.getInstance (InjectorImpl.java:1086)
at org.eclipse.sisu.space.AbstractDeferredClass.get (AbstractDeferredClass.java:48)
at com.google.inject.internal.ProviderInternalFactory.provision (ProviderInternalFactory.java:85)
at com.google.inject.internal.InternalFactoryToInitializableAdapter.provision (InternalFactoryToInitializableAdapter.java:57)
at com.google.inject.internal.ProviderInternalFactory$1.call (ProviderInternalFactory.java:66)
at com.google.inject.internal.ProvisionListenerStackCallback$Provision.provision (ProvisionListenerStackCallback.java:112)
at com.google.inject.internal.ProvisionListenerStackCallback$Provision.provision (ProvisionListenerStackCallback.java:127)
at com.google.inject.internal.ProvisionListenerStackCallback.provision (ProvisionListenerStackCallback.java:66)
at com.google.inject.internal.ProviderInternalFactory.circularGet (ProviderInternalFactory.java:61)
at com.google.inject.internal.InternalFactoryToInitializableAdapter.get (InternalFactoryToInitializableAdapter.java:47)
at com.google.inject.internal.InjectorImpl$1.get (InjectorImpl.java:1050)
at org.eclipse.sisu.inject.Guice4$1.get (Guice4.java:162)
at org.eclipse.sisu.inject.LazyBeanEntry.getValue (LazyBeanEntry.java:81)
at org.eclipse.sisu.plexus.LazyPlexusBean.getValue (LazyPlexusBean.java:51)
at org.codehaus.plexus.DefaultPlexusContainer.lookup (DefaultPlexusContainer.java:263)
at org.codehaus.plexus.DefaultPlexusContainer.lookup (DefaultPlexusContainer.java:255)
at org.apache.maven.plugin.internal.DefaultMavenPluginManager.getConfiguredMojo (DefaultMavenPluginManager.java:520)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:124)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:78)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:567)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)

Unable to build docker image in one step

Hi,

The current docker file requires a maven build to occur first, which requires a user to set up Java and Maven on their local machine.

By using Docker multi-stage builds https://docs.docker.com/build/building/multi-stage/ the requirement for a local Java and Maven setup can be removed.

Below is an example of how this can be done.

Thanks

Mark

#
# mark-sivill-kong - Dec 2022
# 
FROM openjdk:8-jdk-alpine

WORKDIR /swagger-petstore

RUN apk add maven

COPY src/ /swagger-petstore/src
COPY pom.xml /swagger-petstore/pom.xml

RUN mvn --quiet package

#
# copy build assets into run
#
FROM openjdk:8-jre-alpine

WORKDIR /swagger-petstore

COPY src/main/resources/openapi.yaml /swagger-petstore/openapi.yaml
COPY inflector.yaml /swagger-petstore/
COPY --from=0 /swagger-petstore/target/lib/jetty-runner.jar /swagger-petstore/jetty-runner.jar
COPY --from=0 /swagger-petstore/target/*.war /swagger-petstore/server.war

EXPOSE 8080

CMD ["java", "-jar", "-DswaggerUrl=openapi.yaml", "/swagger-petstore/jetty-runner.jar", "--log", "/var/log/yyyy_mm_dd-requests.log", "/swagger-petstore/server.war"]

The openapi-inflector.yaml file is missing

After runnung - "mvn package jetty:run" - I get error "file not found openapi-inflector.yaml in main/java/resources". I duplicated, renamed, and placed inflector.yaml into this directory. So the application launch command worked correctly. I think this might help other developers.

The API method /pet/{petId}/uploadImage fails when a Pet has no PhotoUrls array defined

When you add a Pet without an empty string array for PhotoUrls, and then try to upload an image, the following code fails:

existingPet.getPhotoUrls().add(file.getAbsolutePath());
2020-01-02T06:51:14.281833899Z: [INFO]  	at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:118) [jetty-runner.jar:9.4.9.v20180320]
2020-01-02T06:51:14.281849199Z: [INFO]  	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:754) [jetty-runner.jar:9.4.9.v20180320]
2020-01-02T06:51:14.281853099Z: [INFO]  	at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:672) [jetty-runner.jar:9.4.9.v20180320]
2020-01-02T06:51:14.298147159Z: [INFO]  	at java.lang.Thread.run(Thread.java:748) [na:1.8.0_212]
2020-01-02T06:51:14.298160260Z: [INFO]  Caused by: java.lang.reflect.InvocationTargetException: null
2020-01-02T06:51:14.298165260Z: [INFO]  	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_212]
2020-01-02T06:51:14.298169560Z: [INFO]  	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_212]
2020-01-02T06:51:14.298173660Z: [INFO]  	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_212]
2020-01-02T06:51:14.298177860Z: [INFO]  	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_212]
2020-01-02T06:51:14.298181960Z: [INFO]  	at io.swagger.oas.inflector.controllers.OpenAPIOperationController.apply(OpenAPIOperationController.java:435) ~[swagger-inflector-2.0.2.jar:2.0.2]
2020-01-02T06:51:14.298186160Z: [INFO]  	... 56 common frames omitted
2020-01-02T06:51:14.298190060Z: [INFO]  Caused by: java.lang.NullPointerException: null
2020-01-02T06:51:14.298199960Z: [INFO]  	at io.swagger.petstore.controller.PetController.uploadFile(PetController.java:142) ~[classes/:na]
2020-01-02T06:51:14.298204560Z: [INFO]  	... 61 common frames omitted
2020-01-02T06:51:14.298209660Z: [INFO]  06:51:14.278 [qtp1775282465-21] DEBUG i.s.o.i.utils.DefaultExceptionMapper - checking type application/json against io.swagger.oas.inflector.processors.JacksonProcessor

Maven War Plugin is missing

Without specifying the maven war plugin following error happens:
"plugin 'org.apache.maven.plugins:maven-war-plugin:2.2' due to an API incompatibility: org.codehaus.plexus.component.repository.exception.ComponentLookupException: Cannot access defaults field of Properties"

Furthermore after explicitly specifying the maven war plugin a lot of warnings appear during " mvn package jetty:run" and at the end jetty is not working because of
"Failed to execute goal org.eclipse.jetty:jetty-maven-plugin:9.4.53.v20231009:run (default-cli) on project swagger-petstore: Failure: Error forming scan list: Not file or doesn't exist: D:\dev\apps\swagger-petstore-master\src\main\resources\openapi-inflector.yaml"

/store/inventory returns 500 server error

When invoked in the following manner, the endpoint returns a 500 server error:

curl \
  --request POST \
  --url 'http://localhost:8080/v3/store/order' \
  --header 'Content-Type: application/json' \
  --data '{"id":456,"petId":456,"quantity":2}' \
  --location \
  --max-redirs 32

curl \
  --request GET \
  --url 'http://localhost:8080/v3/store/order/456' \
  --header 'Content-Type: application/json' \
  --location \
  --max-redirs 32

curl \
  --request GET \
  --url 'http://localhost:8080/v3/store/inventory' \
  --header 'Content-Type: application/json' \
  --header 'api_key: special-key' \
  --location \
  --max-redirs 32

GET /user/login and GET /user/{username} has conflict

I think these two APIs defined inside swagger pet store has conflict:

GET /user/login
GET /user/{username}

If I create a user with name login, then if I want to get the user profile, I need to call GET /user/login, then it will redirect to login page, and cannot get profile for user "login"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.