Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Latest commit

 

History

History
431 lines (380 loc) · 32.9 KB

File metadata and controls

431 lines (380 loc) · 32.9 KB

This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose.

This Java package is automatically generated by the OpenAPI JSON Schema Generator project:

  • API version: 1.0.0
  • Package version:
  • Build package: JavaClientGenerator

Requirements

  1. Java 17
  2. Maven

Installation

To install the API client library to your local Maven repository, simply execute:

mvn clean install

To deploy it to a remote Maven repository instead, configure the settings of the repository and execute:

mvn clean deploy

Refer to the OSSRH Guide for more information.

Maven users

Add this dependency to your project's POM:

<dependency>
  <groupId>org.openapijsonschematools</groupId>
  <artifactId>petstore</artifactId>
  <version>1.0.0</version>
  <scope>compile</scope>
</dependency>

Others

At first generate the JAR by executing:

mvn clean package

Then manually install the following JARs:

  • target/petstore-1.0.0.jar
  • target/lib/*.jar

Usage Notes

Validation, Immutability, and Data Type

This Java code validates data to schema classes and return back an immutable instance containing the data. This ensure that

  • valid data cannot be mutated and become invalid to a set of schemas
    • the one exception is that files are not immutable, so schema instances storing/sending/receiving files are not immutable

Here is the mapping from json schema types to Java types:

Json Schema Type Java Base Class
object FrozenMap (HashMap)
array FrozenList (ArrayList)
string String
number Number (int, long, float, double)
integer int, long, float, double (with values equal to integers)
boolean boolean
null Void (null)
AnyType (unset) @Nullable Object

Storage of Json Schema Definition in Java JsonSchema Classes

In openapi v3.0.3 there are ~ 28 json schema keywords. Almost all of them can apply if type is unset. I have chosen to separate the storage of

  • json schema definition info
  • output classes for validated Map (json schema type object) payloads
  • output classes for validated List (json schema type array) payloads
Reason

This json schema data is stored in each class that is written for a schema, in a component or other openapi document location. This class is only responsible for storing schema info. Output classes like those that store map payloads are written separately and are returned by the JsonSchema.validate method when that method is passed in Map input. This prevents payload property access methods from colliding with json schema definition.

Json Schema Type Object

Most component schemas (models) are probably of type object. Which is a map data structure. Json schema allows string keys in this map, which means schema properties can have key names that are invalid Java variable names. Names like:

  • "hi-there"
  • "1variable"
  • "@now"
  • " "
  • "from"

To allow these use cases to work, FrozenMap (which extends HashMap) is used as the base class of type object schemas. This means that one can use normal Map methods on instances of these classes.

Other Details
  • getters are written for validly named required and optional properties
  • null is only allowed in as a value if type: "null" was included or nullable: true was set
    • because null is an allowed property value, it is not used to represent an unset property state
  • if an optional property is requested and it does not exist in the Map, an UnsetPropertyException is thrown

Json Schema Type + Format, Validated Data Storage

N schemas can be validated on the same payload. To allow multiple schemas to validate, the data must be stored using one base class whether or not a json schema format constraint exists in the schema. See the below accessors for string data:

  • type string + format: See schemas.as_date, schemas.as_datetime, schemas.as_decimal, schemas.as_uuid

In json schema, type: number with no format validates both integers and floats, so int and float values are stored for type number.

String + Date Example

For example the string payload '2023-12-20' is validates to both of these schemas:

  1. string only
- type: string
  1. string and date format
- type: string
  format: date

Because of use cases like this, a datetime.date is allowed as an input to this schema, but the data is stored as a string.

Getting Started

Please follow the installation procedure and then use the JsonSchema classes in org.openapijsonschematools.client.components.schemas to validate input payloads and instances of validated Map and List output classes. Json schemas allow multiple types for one schema, so a schema's validate method can have allowed input and output types.

Servers

server_index Class Description
0 Server0 petstore server
1 Server1 The local server
2 Server2 staging server with no variables

Component Schemas

Class Description
Schema200Response.Schema200Response1 model with an invalid class name for python, starts with a number
AbstractStepMessage.AbstractStepMessage1 Abstract Step
AdditionalPropertiesClass.AdditionalPropertiesClass1
AdditionalPropertiesSchema.AdditionalPropertiesSchema1
AdditionalPropertiesWithArrayOfEnums.AdditionalPropertiesWithArrayOfEnums1
Address.Address1
Animal.Animal1
AnimalFarm.AnimalFarm1
AnyTypeAndFormat.AnyTypeAndFormat1
AnyTypeNotString.AnyTypeNotString1
ApiResponseSchema.ApiResponseSchema1
ArrayHoldingAnyType.ArrayHoldingAnyType1
ArrayOfArrayOfNumberOnly.ArrayOfArrayOfNumberOnly1
ArrayOfEnums.ArrayOfEnums1
ArrayOfNumberOnly.ArrayOfNumberOnly1
ArrayTest.ArrayTest1
ArrayWithValidationsInItems.ArrayWithValidationsInItems1
Bar.Bar1
BasquePig.BasquePig1
BooleanSchema.BooleanSchema1
BooleanEnum.BooleanEnum1
Capitalization.Capitalization1
Cat.Cat1
Category.Category1
ChildCat.ChildCat1
ClassModel.ClassModel1 Model for testing model with "_class" property
Client.Client1
ComplexQuadrilateral.ComplexQuadrilateral1
ComposedAnyOfDifferentTypesNoValidations.ComposedAnyOfDifferentTypesNoValidations1
ComposedArray.ComposedArray1
ComposedBool.ComposedBool1
ComposedNone.ComposedNone1
ComposedNumber.ComposedNumber1
ComposedObject.ComposedObject1
ComposedOneOfDifferentTypes.ComposedOneOfDifferentTypes1 this is a model that allows payloads of type object or number
ComposedString.ComposedString1
Currency.Currency1
DanishPig.DanishPig1
DateTimeTest.DateTimeTest1
DateTimeWithValidations.DateTimeWithValidations1
DateWithValidations.DateWithValidations1
DecimalPayload.DecimalPayload1
Dog.Dog1
Drawing.Drawing1
EnumArrays.EnumArrays1
EnumClass.EnumClass1
EnumTest.EnumTest1
EquilateralTriangle.EquilateralTriangle1
File.File1 Must be named `File` for test.
FileSchemaTestClass.FileSchemaTestClass1
Foo.Foo1
FormatTest.FormatTest1
FromSchema.FromSchema1
GrandparentAnimal.GrandparentAnimal1
HealthCheckResult.HealthCheckResult1 Just a string to inform instance is up and running. Make it nullable in hope to get it as pointer in generated model.
IntegerEnum.IntegerEnum1
IntegerEnumBig.IntegerEnumBig1
IntegerEnumOneValue.IntegerEnumOneValue1
IntegerEnumWithDefaultValue.IntegerEnumWithDefaultValue1
IntegerMax10.IntegerMax101
IntegerMin15.IntegerMin151
IsoscelesTriangle.IsoscelesTriangle1
Items.Items1 component's name collides with the inner schema name
JSONPatchRequest.JSONPatchRequest1
JSONPatchRequestAddReplaceTest.JSONPatchRequestAddReplaceTest1
JSONPatchRequestMoveCopy.JSONPatchRequestMoveCopy1
JSONPatchRequestRemove.JSONPatchRequestRemove1
MapTest.MapTest1
MixedPropertiesAndAdditionalPropertiesClass.MixedPropertiesAndAdditionalPropertiesClass1
Money.Money1
MyObjectDto.MyObjectDto1
Name.Name1 Model for testing model name same as property name
NoAdditionalProperties.NoAdditionalProperties1
NullableClass.NullableClass1
NullableShape.NullableShape1 The value may be a shape or the 'null' value. For a composed schema to validate a null payload, one of its chosen oneOf schemas must be type null or nullable (introduced in OAS schema >= 3.0)
NullableString.NullableString1
NumberSchema.NumberSchema1
NumberOnly.NumberOnly1
NumberWithExclusiveMinMax.NumberWithExclusiveMinMax1
NumberWithValidations.NumberWithValidations1
ObjWithRequiredProps.ObjWithRequiredProps1
ObjWithRequiredPropsBase.ObjWithRequiredPropsBase1
ObjectInterface.ObjectInterface1
ObjectModelWithArgAndArgsProperties.ObjectModelWithArgAndArgsProperties1
ObjectModelWithRefProps.ObjectModelWithRefProps1 a model that includes properties which should stay primitive (String + Boolean) and one which is defined as a class, NumberWithValidations
ObjectWithAllOfWithReqTestPropFromUnsetAddProp.ObjectWithAllOfWithReqTestPropFromUnsetAddProp1
ObjectWithCollidingProperties.ObjectWithCollidingProperties1 component with properties that have name collisions
ObjectWithDecimalProperties.ObjectWithDecimalProperties1
ObjectWithDifficultlyNamedProps.ObjectWithDifficultlyNamedProps1 model with properties that have invalid names for python
ObjectWithInlineCompositionProperty.ObjectWithInlineCompositionProperty1
ObjectWithInvalidNamedRefedProperties.ObjectWithInvalidNamedRefedProperties1
ObjectWithNonIntersectingValues.ObjectWithNonIntersectingValues1
ObjectWithOnlyOptionalProps.ObjectWithOnlyOptionalProps1
ObjectWithOptionalTestProp.ObjectWithOptionalTestProp1
ObjectWithValidations.ObjectWithValidations1
Order.Order1
PaginatedResultMyObjectDto.PaginatedResultMyObjectDto1
ParentPet.ParentPet1
Pet.Pet1 Pet object that needs to be added to the store
Pig.Pig1
Player.Player1 a model that includes a self reference this forces properties and additionalProperties to be lazy loaded in python models because the Player class has not fully loaded when defining properties
PublicKey.PublicKey1 schema that contains a property named key
Quadrilateral.Quadrilateral1
QuadrilateralInterface.QuadrilateralInterface1
ReadOnlyFirst.ReadOnlyFirst1
RefPet.RefPet1
ReqPropsFromExplicitAddProps.ReqPropsFromExplicitAddProps1
ReqPropsFromTrueAddProps.ReqPropsFromTrueAddProps1
ReqPropsFromUnsetAddProps.ReqPropsFromUnsetAddProps1
ReturnSchema.ReturnSchema1 Model for testing reserved words
ScaleneTriangle.ScaleneTriangle1
SelfReferencingArrayModel.SelfReferencingArrayModel1
SelfReferencingObjectModel.SelfReferencingObjectModel1
Shape.Shape1
ShapeOrNull.ShapeOrNull1 The value may be a shape or the 'null' value. This is introduced in OAS schema >= 3.1.
SimpleQuadrilateral.SimpleQuadrilateral1
SomeObject.SomeObject1
StringSchema.StringSchema1
StringBooleanMap.StringBooleanMap1
StringEnum.StringEnum1
StringEnumWithDefaultValue.StringEnumWithDefaultValue1
StringWithValidation.StringWithValidation1
Tag.Tag1
Triangle.Triangle1
TriangleInterface.TriangleInterface1
UUIDString.UUIDString1
User.User1
SpecialModelname.SpecialModelname1 model with an invalid class name for python
Apple.Apple1
AppleReq.AppleReq1
Banana.Banana1
BananaReq.BananaReq1
Fruit.Fruit1
FruitReq.FruitReq1
GmFruit.GmFruit1
HasOnlyReadOnly.HasOnlyReadOnly1
Mammal.Mammal1
Whale.Whale1
Zebra.Zebra1

Endpoints

All URIs are relative to the selected server

  • The server is selected by passing in serverInfo into configurations.ApiConfiguration
  • The security info is selected by passing in securityInfo into configurations.ApiConfiguration
  • TODO Code samples in endpoints documents show how to do this
  • serverIndex + securityIndex can also be passed in to endpoint calls, see endpoint documentation
HTTP request Method Description
/ get Get1.get slash route
/another-fake/dummy patch Patch1.patch To test special tags
/commonParam/{subDir}/ delete Delete1.delete
/commonParam/{subDir}/ get Get1.get
/commonParam/{subDir}/ post Post1.post
/fake delete Delete1.delete Fake endpoint to test group parameters (optional)
/fake get Get1.get To test enum parameters
/fake patch Patch1.patch To test "client" model
/fake post Post1.post Fake endpoint for testing various parameters
假端點
偽のエンドポイント
가짜 엔드 포인트
/fake/additional-properties-with-array-of-enums get Get1.get Additional Properties with Array of Enums
/fake/body-with-file-schema put Put1.put
/fake/body-with-query-params put Put1.put
/fake/case-sensitive-params put Put1.put
/fake/deleteCoffee/{id} delete Delete1.delete Delete coffee
/fake/health get Get1.get Health check endpoint
/fake/inline-additionalProperties post Post1.post test inline additionalProperties
/fake/inlineComposition/ post Post1.post testing composed schemas at inline locations
/fake/jsonFormData get Get1.get test json serialization of form data
/fake/jsonPatch patch Patch1.patch json patch
/fake/jsonWithCharset post Post1.post json with charset tx and rx
/fake/multipleRequestBodyContentTypes/ post Post1.post testing composed schemas at inline locations
/fake/multipleResponseBodies get Get1.get multiple responses have response bodies
/fake/multipleSecurities get Get1.get multiple security requirements
/fake/objInQuery get Get1.get user list
/fake/parameterCollisions/{1}/{aB}/{Ab}/{self}/{A-B}/ post Post1.post parameter collision case
/fake/pemContentType get Get1.get route with tx and rx pem content type
/fake/queryParamWithJsonContentType get Get1.get query param with json content-type
/fake/redirection get Get1.get operation with redirection responses
/fake/refObjInQuery get Get1.get user list
/fake/refs/array-of-enums post Post1.post Array of Enums
/fake/refs/arraymodel post Post1.post
/fake/refs/boolean post Post1.post
/fake/refs/composed_one_of_number_with_validations post Post1.post
/fake/refs/enum post Post1.post
/fake/refs/mammal post Post1.post
/fake/refs/number post Post1.post
/fake/refs/object_model_with_ref_props post Post1.post
/fake/refs/string post Post1.post
/fake/responseWithoutSchema get Get1.get receives a response without schema
/fake/test-query-paramters put Put1.put
/fake/uploadDownloadFile post Post1.post uploads a file and downloads a file using application/octet-stream
/fake/uploadFile post Post1.post uploads a file using multipart/form-data
/fake/uploadFiles post Post1.post uploads files using multipart/form-data
/fake/wildCardResponses get Get1.get operation with wildcard responses
/fake/{petId}/uploadImageWithRequiredFile post Post1.post uploads an image (required)
/fake_classname_test patch Patch1.patch To test class name in snake case
/foo get Get1.get
/pet post Post1.post Add a new pet to the store
/pet put Put1.put Update an existing pet
/pet/findByStatus get Get1.get Finds Pets by status
/pet/findByTags get Get1.get Finds Pets by tags
/pet/{petId} delete Delete1.delete Deletes a pet
/pet/{petId} get Get1.get Find pet by ID
/pet/{petId} post Post1.post Updates a pet in the store with form data
/pet/{petId}/uploadImage post Post1.post uploads an image
/store/inventory get Get1.get Returns pet inventories by status
/store/order post Post1.post Place an order for a pet
/store/order/{order_id} delete Delete1.delete Delete purchase order by ID
/store/order/{order_id} get Get1.get Find purchase order by ID
/user post Post1.post Create user
/user/createWithArray post Post1.post Creates list of users with given input array
/user/createWithList post Post1.post Creates list of users with given input array
/user/login get Get1.get Logs user into the system
/user/logout get Get1.get Logs out current logged in user session
/user/{username} delete Delete1.delete Delete user
/user/{username} get Get1.get Get user by user name
/user/{username} put Put1.put Updated user

Component RequestBodies

Class Description
Client.Client1 client model
Pet.Pet1 Pet object that needs to be added to the store, multiple content types
RefUserArray.RefUserArray1
UserArray.UserArray1 List of user object

Component Responses

Class Description
HeadersWithNoBody.HeadersWithNoBody1 A response that contains headers but no body
RefSuccessDescriptionOnly.RefSuccessDescriptionOnly1
RefSuccessfulXmlAndJsonArrayOfPet.RefSuccessfulXmlAndJsonArrayOfPet1
SuccessDescriptionOnly.SuccessDescriptionOnly1 Success
SuccessInlineContentAndHeader.SuccessInlineContentAndHeader1 successful operation
SuccessWithJsonApiResponse.SuccessWithJsonApiResponse1 successful operation
SuccessfulXmlAndJsonArrayOfPet.SuccessfulXmlAndJsonArrayOfPet1 successful operation, multiple content types

Component Headers

Class Description
Int32JsonContentTypeHeader.Int32JsonContentTypeHeader1 int32 JSON content-type header
NumberHeader.NumberHeader1 number header description
RefContentSchemaHeader.RefContentSchemaHeader1 int32 JSON content-type header
RefSchemaHeader.RefSchemaHeader1 header that has a ref in the schema
RefStringHeader.RefStringHeader1
StringHeader.StringHeader1 string header description

Component Parameters

Class Description
ComponentRefSchemaStringWithValidation.ComponentRefSchemaStringWithValidation1 a path string with validation
PathUserName.PathUserName1 the use name to use
RefPathUserName.RefPathUserName1
RefSchemaStringWithValidation.RefSchemaStringWithValidation1 a path string with validation

Component SecuritySchemes

Class Description
ApiKey apiKey in header
ApiKeyQuery apiKey in query
BearerTest http bearer with JWT bearer format
HttpBasicTest http basic
HttpSignatureTest http + signature
OpenIdConnectTest openIdConnect
PetstoreAuth oauth2 implicit flow with two scopes