Fixed generating class for properties with empty properties
Codegen doesn't generate class when an object defined with an empty
properties list. When an object named risk property defined with empty properties list generator defines it as java.lang.Object. But when reading the object with ObjectMapper it doesn't read risk : {}.
PR checklist
- [x] Read the contribution guidelines.
- [ ] Ran the shell script under
./bin/to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.shand./bin/security/{LANG}-petstore.shif updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\. - [x] Filed the PR against the correct branch:
3.0.0branch for changes related to OpenAPI spec 3.0. Default:master. - [ ] Copied the technical committee to review the pull request if your PR is targeting a particular programming language.
Description of the PR
swagger: '2.0'
info:
title: Account and Transaction API Specification
description: Swagger for Account and Transaction API Specification
termsOfService: https://www.openbanking.org.uk/terms
contact:
name: Service Desk
email: [email protected]
license:
name: open-licence
url: https://www.openbanking.org.uk/open-licence
version: v1.1.0
basePath: /open-banking/v1.1
schemes:
- https
produces:
- application/json; charset=utf-8
paths:
/hello:
post:
summary: Say hello
description: Say hello
operationId: sayHello
consumes:
- application/json; charset=utf-8;
produces:
- application/json; charset=utf-8;
parameters:
- in : body
name: body
description: Setup to say hello
required: true
schema:
title: Hello setup POST request
description: Allows a hello setup
type: object
properties:
Data:
description: ''
title: Hello Setup
type: object
properties:
Greeting:
description: 'greeting'
type: string
required:
- Greeting
additionalProperties: false
Risk:
description: ''
title: Risk
type: object
properties: {}
additionalProperties: false
required:
- Data
- Risk
additionalProperties: false
responses:
201:
description: Greet back
schema:
title: Greet back POST response
type: object
properties:
Helloback:
description: Hello back
type: string
Codegen does not generate a class for Risk. And generates the HelloSetupPOSTRequest with variables Data data and java.lang.Object Risk.
Codegen doesn't generate class when an object defined with an empty properties list
Can you share more about the use case with an empty properties list?
I added an example yaml file @wing328
@korkut89 sorry I mean why an object is defined without properties? I think only a handful of programming languages support empty object (an object without property)
What does the corresponding JSON payload look like?
{
"Data" : {
"Greeting" : "Hi"
},
"Risk": {}
}
It should look something like that.
@korkut89 thanks for sharing more. Given that the JSON payload is well-defined, why define it as an empty object?
@wing328 https://github.com/OpenBankingUK/account-info-api-spec/blob/master/dist/v1.1/account-info-swagger.yaml We are using this spec. Since this spec defined as standard for open banking we must use this. I am not sure why it was defined as an empty object.
@korkut89 I think the spec owner will need to update the spec to have a proper definition of the model with valid properties instead.
@wing328 well, although weird, this spec is valid. So we should generate something correct. The filter on the properties size was introduced by #2297 so the impact of changing it has to be carefully studied as regards to the issue it was solving.
I think this spec is likely to be updated in the long run. But can't say for certain that it is going to change. I agree with @cbornet this is a valid spec.
I agreed with you guys the spec is valid according to the specification.
My point is without knowing how the object (JSON, XML) is defined, how can any developers figure out how to process the object?
The issue is nothing swagger-codegen-specified. Someone who is manually writing the client will also encounter the same issue.
To me, Risk should be a class with no attributes, no ?