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]
> <mailto:[email protected]>.
> For more options, visit https://groups.google.com/d/optout
> <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.