I can certainly appreciate the sentiment and generally don't disagree, however my hands are a bit tied here and I'm wondering if its possible to do what I asked above.
On Thu, Feb 23, 2017 at 11:23 AM, Ron Ratovsky <[email protected]> wrote: > If the spec doesn’t match the returned object, then shame on the spec > writer or code writer, whoever came last. The spec is there to document the > API. > > > > > > *From: *<[email protected]> on behalf of Abdullah > Mourad <[email protected]> > *Reply-To: *"[email protected]" < > [email protected]> > *Date: *Thursday, 23 February 2017 at 11:20 > *To: *Swagger <[email protected]> > *Subject: *Re: how to write the swagger definition for json response > > > > On a related note... What would one do if the spec did not match the > returned object. Is there any way to map between the two, rather than write > the spec to match the object? > > > > Let's say you have > > > > "definitions": { > > "Foo": { > > "properties": { > > "projectName": { > > "type": "string" > > } > > }, > > "type": "object" > > } > > } > > > > And your serverside object come back: > > > > "project": > > { > > "projNm": "some name", > > "projId": "some other property", > > } > > , > > > Is there anyway to map projectName property to project.projNm from the > response? How about handling this the other way, when I am given > projectName as an input and want it converted project.projNm server-side? > > > > > On Thursday, February 23, 2017 at 10:22:09 AM UTC-8, tony tam wrote: > > I suggest you try out the http://editor.swagger.io to experiment with the > specification. But here’s how it could be done: > > > > > > # as a single inline object definition > > definitions: > > YourResponse: > > type: object > > properties: > > Data: > > type: object > > properties: > > Login: > > type: array > > items: > > type: object > > properties: > > name: > > type: string > > example: Doe > > firstname: > > type: string > > example: John > > id: > > type: integer > > format: int64 > > example: 461199 > > password-expiry-utc: > > type: integer > > example: 20170223163054 > > > > # or in a flatter style using JSON references > > definitions: > > YourResponse: > > type: object > > properties: > > Data: > > $ref: '#/definitions/DataObject' > > DataObject: > > type: object > > properties: > > Login: > > type: array > > items: > > $ref: '#/definitions/LoginRequest' > > LoginRequest: > > type: object > > properties: > > name: > > type: string > > example: Doe > > firstname: > > type: string > > example: John > > id: > > type: integer > > format: int64 > > example: 461199 > > password-expiry-utc: > > type: integer > > example: 20170223163054 > > > > > > On Feb 23, 2017, at 8:46 AM, BG <[email protected]> wrote: > > > > Hi, > > > > I have this rather simple json response, in my swagger file I want to > write the definition that matches the response. > > I got stuck - probably because because I am new to swagger. > > > > so at the end of the example below i want the definition for this json > response > > > > {"Data":{"Login":[{"name":"Doe","firstname":"John","id":461199, > "passhash-expiry-utc":"20170223163054"}]}} > > > > below is how my swagger looks now. Can anyone get my back on track by > providing an example on how to write the definition? > > > > thanks! > > > > swagger: '2.0' > > info: > > version: ' 1.13.0003.00' > > title: test (Simple) > > description: An API > > termsOfService: > > contact: > > name: Contoso > > email: [email protected] > > url: http://mydomain.com > > license: > > name: MIT > > url: http://opensource.org/licenses/MIT > > host: mydomain.com > > basePath: /api > > schemes: > > - http > > - https > > consumes: > > - application/json > > produces: > > - application/json > > paths: > > /login: > > get: > > description: > > 'Returns basis user properties and passhash expiry date/time stamp > > > > as > > > > {"Data":{"Login":[{"name":"Doe","firstname":"John","id": > 461199,"passhash-expiry-utc":"20170223163054"}]}} > > > > ' > > operationId: login > > produces: > > - application/json > > parameters: > > - name: pswauth > > in: query > > description: pswauthstring > > required: true > > type: string > > responses: > > '200': > > description: login response > > schema: > > type: array > > items: > > $ref: '#/definitions/Login' > > 'default': > > description: unexpected error > > schema: > > $ref: '#/definitions/errorModel' > > definitions: > > errorModel: > > type: object > > required: > > - code > > - message > > properties: > > code: > > type: integer > > format: int32 > > message: > > type: string > > Login: > > type: object > > required: > > - code > > - message > > properties: > > code: > > type: integer > > format: int32 > > message: > > type: string > > > > > > > > -- > You received this message because you are subscribed to the Google Groups > "Swagger" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > > > > -- > You received this message because you are subscribed to the Google Groups > "Swagger" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > > -- > You received this message because you are subscribed to a topic in the > Google Groups "Swagger" group. > To unsubscribe from this topic, visit https://groups.google.com/d/ > topic/swagger-swaggersocket/NZ5glQR6Quw/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Swagger" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
