Bug Report Checklist
Description
Parsing should fail when required fields are not present in input.
Generated code with jaxrs-spec / jackson accepts json with missing required fields.
For this to work with jackson, the following are needed:
- required fields need be passed in parameter of a constructor annotated with @JsonCreator
- each constructor parameter representing a required field need to be annotated with @JsonProperty(value = "fieldName", required = true)
See sections 2.1 and 2.2 of this doc: https://www.novixys.com/blog/jackson-annotations-guide/#21_Confusion_with_required / https://www.novixys.com/blog/jackson-annotations-guide/#22_JsonProperty_and_JsonCreator
openapi-generator version
7.9.0-SNAPSHOT
This is not a regression as far as I can tell
OpenAPI declaration file content or url
If you post the code inline, please wrap it with
openapi: 3.0.0
info:
title: Test
version: '1.0'
paths:
'/test':
get:
requestBody:
content:
application/vnd.amadeus+json:
schema:
type: object
title: TestObject
required:
- id
properties:
id:
type: string
responses:
'200':
description: OK
Here TestObject.id is a required field
Generation Details
java -jar openapi-generator-cli.jar generate -o ./generated -i ./test-api.yaml -g jaxrs-spec --additional-properties=generateBuilders=true,serializationLibrary=jackson
Steps to reproduce
Save the API declaration in a file and generate it.
Deserializing empty json with generated code does not fail
objectMapper.readValue("{}", TestObject.class)
This code is supposed to thow MismatchedInputException since we didnt give "id" property in input.
Related issues/PRs
No, but other generators like "java" generate code with JsonCreator / JsonProperty
Suggest a fix
I will submit a PR with the template override with use for pojo.mustache
Bug Report Checklist
Description
Parsing should fail when required fields are not present in input.
Generated code with jaxrs-spec / jackson accepts json with missing required fields.
For this to work with jackson, the following are needed:
See sections 2.1 and 2.2 of this doc: https://www.novixys.com/blog/jackson-annotations-guide/#21_Confusion_with_required / https://www.novixys.com/blog/jackson-annotations-guide/#22_JsonProperty_and_JsonCreator
openapi-generator version
7.9.0-SNAPSHOT
This is not a regression as far as I can tell
OpenAPI declaration file content or url
If you post the code inline, please wrap it with
Here TestObject.id is a required field
Generation Details
java -jar openapi-generator-cli.jar generate -o ./generated -i ./test-api.yaml -g jaxrs-spec --additional-properties=generateBuilders=true,serializationLibrary=jackson
Steps to reproduce
Save the API declaration in a file and generate it.
Deserializing empty json with generated code does not fail
This code is supposed to thow MismatchedInputException since we didnt give "id" property in input.
Related issues/PRs
No, but other generators like "java" generate code with JsonCreator / JsonProperty
Suggest a fix
I will submit a PR with the template override with use for pojo.mustache