Open posener opened 6 years ago
I noticed that imposter modified the swagger: It removed the host
and basePath
from root of swagger and added it to each path
entry.
Might it be the reason?
The bravado client used by opencli
uses the host
& basePath
to determine the endpoints URLs. If basePath
is not specified, it defaults to /.
I've tries reproducing your problem but failed doing so, the said command returned
Imposter Mock APIs $ pet addPet --body.name=test
'photoUrls' is a required property
Failed validating 'required' in schema:
{'properties': {'category': {'$ref': '#/definitions/Category',
'x-scope': ['http://localhost:8443/_spec/combined.json']},
'id': {'format': 'int64', 'type': 'integer'},
'name': {'example': 'doggie', 'type': 'string'},
'photoUrls': {'items': {'type': 'string'},
'type': 'array',
'xml': {'name': 'photoUrl',
'wrapped': True}},
'status': {'description': 'pet status in the store',
'enum': ['available', 'pending', 'sold'],
'type': 'string'},
'tags': {'items': {'$ref': '#/definitions/Tag',
'x-scope': ['http://localhost:8443/_spec/combined.json']},
'type': 'array',
'xml': {'name': 'tag', 'wrapped': True}}},
'required': ['name', 'photoUrls'],
'type': 'object',
'x-model': 'Pet',
'xml': {'name': 'Pet'}}
On instance:
{'name': 'test'}
Which is a valid response.
Can you attach the swagger file you've used.
Please
swagger: '2.0'
info:
version: '1.0.0'
title: Minimal Pet Store Example
host: example.org
basePath: /api
schemes: [http]
consumes: [application/json]
produces: [application/json]
paths:
/pets:
post:
tags: [pet]
operationId: Create
parameters:
- in: body
name: pet
required: true
schema:
$ref: '#/definitions/Pet'
responses:
201:
description: Pet Created
schema:
$ref: '#/definitions/Pet'
400:
description: Bad Request
get:
tags: [pet]
operationId: List
parameters:
- in: query
name: category
type: string
responses:
200:
description: 'Pet list'
schema:
type: array
items:
$ref: '#/definitions/Pet'
/pets/{petId}:
get:
tags: [pet]
operationId: Get
parameters:
- name: petId
in: path
required: true
type: integer
format: int64
responses:
200:
description: Pet get
schema:
$ref: '#/definitions/Pet'
400:
description: Bad Request
404:
description: Pet Not Found
definitions:
Pet:
type: object
required:
- name
properties:
id:
type: integer
format: int64
readOnly: true
category:
type: string
name:
type: string
example: doggie
I've tried the opencli with a "imposter" mock server that I ran on the same swagger.yaml.
The command to run the mock server, assuming you have a
swagger.yaml
in CWD:The mock server serves the swagger.json on
http://localhost:8443/_spec/combined.json
- under _spec path. Runningopen-cli http://localhost:8443/_spec/combined.json -v
results in:The open-cli tries to access the api on path
/_spec/combined.json/api/pets
instead of/api/pets
.