-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DefaultCodegen: fix UNKNOWN_BASE_TYPE and "Object" type problem #383
Conversation
I don't understand why the test are not passing since I've done the build with test on my computer without any problem.
|
I am not sure why @wing328 added following code: Lines 4252 to 4264 in 36f4452
See commit 23fc7a8: "rearrange how map, array, model are checked in body request" Your change seems to have no impact on the samples code, because "Shippable" CI generate the most important samples and fail if there are differences with the code that is in the git repository. This is highly possible, because the Petstore or the Fake-Petstore might not have the construct of an I think it would be important to add a unit test to cover your use case. We can use this small spec #185 (comment) (derived from your multiple files) as input. |
Previously, we discovered the issue that a 2.0 spec has the Does your spec have similar issue? |
@wing328 : the case here is definitively an other one. If you take this valid OAS3: openapi: 3.0.1
info:
title: Control Site REST API
description: blablabla
termsOfService: www
version: 1.0.1
servers:
- url: http://localhost:9000/api
paths:
/something:
put:
tags:
- Foo
summary: Update something
operationId: update something
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/EmptyObject'
required: true
responses:
200:
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/DefaultMetaOnlyResponse'
components:
schemas:
EmptyObject:
type: object
description: Empty object used for POST or PUT that doesn't shouldn't have body
but need one to pass play framework validation
ResponseMeta:
required:
- code
type: object
properties:
code:
type: string
description: Code returned by the function
example: Ok
default: Ok
enum:
- Ok
description: Mandatory part of each response given by our API
DefaultMetaOnlyResponse:
required:
- meta
type: object
properties:
meta:
$ref: '#/components/schemas/ResponseMeta'
requestBodies:
empty-body:
content:
application/json:
schema:
$ref: '#/components/schemas/EmptyObject'
required: true Then you also get the warnings in the log and the generated code is: DefaultMetaOnlyResponse logout(Object UNKNOWN_BASE_TYPE) throws Exception; Instead of: DefaultMetaOnlyResponse logout(EmptyObject emptyBody) throws Exception; It works fine if the components:
schemas:
EmptyObject:
type: object
description: Empty object used for POST or PUT that doesn't shouldn't have body
but need one to pass play framework validation
properties:
someProp:
type: string This PR try to solve the case where components:
schemas:
EmptyObject:
type: object
description: Empty object used for POST or PUT that doesn't shouldn't have body
but need one to pass play framework validation Maybe there is an other solution... I did not check in detail for now. |
I'll test it again tomorrow and merge into master if the test result is good. |
Thanks @wing328 |
I am still getting this error after generating a python client. I am using the version 3.2.0 |
@prathik457 Thanks for your reporting. Could you show me your OpenAPI spec file which reproduce the issue? |
Agreed with @ackintosh that we need a spec to reproduce the issue. Your issue may be fixed by #736 (which will be merged later today) |
Oh, I realized that this PR is not released in the version 3.2.0. |
Do you mean you have something fixed with |
Is this supposed to be fixed? I'm not sure if my issue is related, if not I´m sorry but I´m fairly new to this all (OpenApi/Yaml) but I get YAML swagger: '2.0'
info:
title: Swagger
version: '1.0.0'
basePath: /api
schemes:
- https
paths:
/offers/add:
post:
tags:
- offers
operationId: addOffer
consumes:
- application/json
produces:
- application/json
- application/xml
- text/html
parameters:
- in: body
name: body
required: true
schema:
type: object
items:
$ref: '#/definitions/offerDTO'
responses:
'200':
description: OK
schema:
type: array
items:
$ref: '#/definitions/offerDTO'
definitions:
offerDTO:
required:
- id
type: object
properties:
comment:
type: string mustach
With the resulting UNKNOWN_BASE_TYPE [HttpPost]
[Route("/api/offers/add")]
public IActionResult AddOffer([FromBody]UNKNOWN_BASE_TYPE UNKNOWN_BASE_TYPE)
{
} Hope somebody can point me in the right direction for this holiday hack of mine :-) |
If I use openapi-generator-cli-4.0.0-20181226.105224-120.jar from Snapshot (not the latest?) on the the yaml here above I get the following result with Object [HttpPost]
[Route("/api/offers/add")]
public IActionResult AddOffer([FromBody]Object body)
{
} |
Ok heads up, for some reason when I ran it again I get the right result. [HttpPost]
[Route("/api/offers/add")]
public IActionResult AddOffer([FromBody]List<OfferDTO>offerDTO)
{
} I did not change anything.. just ran it again. Probably something to do with my setup. I have a psi script that is run on post build in this project of mine. p.s |
@sturlath your parameters:
- in: body
name: body
required: true
schema:
$ref: '#/definitions/offerDTO' |
PR checklist
./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh
and./bin/security/{LANG}-petstore.sh
if 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\
.master
,3.1.x
,4.0.x
. Default:master
.Description of the PR
This is to fix problem identified here: #185
I didn't run the shell scripts since it touch
DefaultCodegen.java
and I want the advice of the core team before I generate everything. The other reason is that I'm not sure how to re-generate ALL the samples. Will need your help with that :)Feedback is welcome!
@wing328 (2015/07)
@jimschubert (2016/05)
@cbornet (2016/05)
@jaz-ah (2016/05)
@ackintosh (2018/02)
@JFCote (2018/03)
@jmini (2018/04)