swagger model definition for POST and GET methods

swagger model definition for POST and GET methods



I am new to Swagger and open api. I am trying to create a model for an object (let us say "package" object).



For the POST method, I don't define an 'id' parameter, since I expect the back-end system to assign a new UUID for the package being created.



"name": "My Beautiful Package",
"channel": 0,
"status": 0,
"visibility": true



However, for the GET method, the response contains the id (UUID).



"id" : "afefeffbd-384fe3",
"name": "My Beautiful Package",
"channel": 0,
"status": 0,
"visibility": true,
"createdOn": "2018-Sep-08",
"createdBy"" 2234



So, my question is..,



Should I create two models, one for POST methods and one for GET method?



If I define the 'id' field as optional, it might still get shown in the api as one of the optional parameters. This I don't want.



Also, the response to GET package, returns more data such as "date of creation", "created by', etc. How to handle this?



Thanks to anyone clarifying this.






Possible duplicate of Re-using model with different required properties, How to keep the single resource representation approach using OpenAPI spec

– Helen
Sep 8 '18 at 7:25







To recap the linked Q&A - you can have a single model and define GET-only properties as readOnly: true.

– Helen
Sep 8 '18 at 7:27


readOnly: true






Links are useful. I take this to be the answer I am looking for.

– Mopparthy Ravindranath
Sep 8 '18 at 16:38




1 Answer
1



Some example code in typescript i <3 typescript



There would be one class(model) which would take handle use Input, other class that would handle the output.


export class UserInput
username:string,
password:string,
email:String

export class UserData extends UserInput
id or _id : string


export class UserOutput
users : UserData



What this means is :
when you make a post request you use the userInput model
when you user the get request to get a user/list of users you use the userOutput model



fields/columns like "date of creation", "created by', etc. would automatically be handeled by your data model.






Dear Bro, I upvoted your answer to neutralize the downvote by someone. I don't like ppl downvoting without justifying why they do so. May be to exhibit their ego. You have attempted honestly to answer the question. My thumbs up to you.

– Mopparthy Ravindranath
Sep 8 '18 at 16:23



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)