swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
17.01k stars 6.03k forks source link

get specific result node on json #3206

Open Ziaccro opened 8 years ago

Ziaccro commented 8 years ago
Description

Hello, i want to know if there is a option to set a specif node to get the result of the json ?

All endpoint of our api return same schema response ApiResult[T], for exemple when i get user with findById, on the node result i get the User ApiResult[User]

{
  "error": {
  },
  "result": { 
      "email": "",
       ...
  },
  "debug": {
  },
  "meta": {
  }
}

the user is on node result

the problem is, on swagger spec we define as return the model User, on error we describes Error ect ...

in the spec swagger we can't template this and its not a good idea of write model ApiResultUser, ApiResultAddress, ApiResultEnterprise, ... the number of class is huge

i hope there is a workaround, a way to change the method ApiInvoked.deserialize ?

otherwise the code generate is not usable, that fail on the validation of json

wing328 commented 8 years ago

As a workaround, you can describe result as type: object, which means arbitrary JSON object and the developers will need to deserialize the object themselves.

Ziaccro commented 8 years ago

you mean all the json return as object or just the node result ?

with this solution I lose clarity on documentation and its unfortunate to force the user to reparse json

I will try to modify the swagger-codegen and add "general scheme" on it

can you give me some file name from what started reading the code please ?

wing328 commented 8 years ago

Just the node result.

Can you share the full spec?

Ziaccro commented 8 years ago

yes sure its here https://test-api.particeep.com/docs/swagger.json