Comments (4)
Thanks again for the detailed explanation.
I have the utility ready. I need to carry out some more tests and write some documentation. I'll update this thread by EOD tomorrow.
from camouflage.
Thanks @jeroenherczeg for the detailed description and the resources. To be honest, I haven't worked with OpenAPI specs much so the resources were specially helpful. Also the suggestion that this should be an external utility and not something bundled with Camouflage, was on point.
Here's an update from my end. I already have a working prototype of the conversion utility.
- The utility takes in a spec file via command like parameter -s/--spec. And the location of the current mocks directory via -m/--mock.
- It validates if the file exists.
- If the file exists, it checks if the input file is a valid OpenAPI definition
- If that check too passes, it extracts the URLs from the spec file and store them into an array.
- Replaces all the path parameters with wildcards.
- In final step, it creates the mock files for each path specified in spec file.
A generic format of the files created is:
${MOCKS_DIR}/${PATH}/${METHOD}.mock
where:
- ${MOCKS_DIR} is the path of mocks directory specified by -m/--mocks parameter;
- ${PATH} is the individual path element from the array of url paths extracted from spec file (path parameters replaced with wildcards)
- ${METHOD} is the HTTP Method for each url extracted from the spec file
Since I couldn't find this information anywhere, could you please help answer following query?
Is there a way we can populate the contents of the mock files too? Does the spec file also contain the expected responses for the specified URLs? If yes, would you be able help with an example?
from camouflage.
Example: https://gist.github.com/jeroenherczeg/ae76732cca9c2e078a3e466829b47b3a
So for the path '/users/{userId}' we define a GET and a PATCH.
In the request we require query parameter called userId.
The GET request has 2 responses a 200 and a 404.
The 200 also returns a body in json.
This document has example data.
{
"id": 142,
"firstName": "Alice",
"lastName": "Smith",
"email": "[email protected]",
"dateOfBirth": "1997-10-31",
"emailVerified": true,
"signUpDate": "2019-08-24"
}
Examples are optional, but there is always a schema object defining the response body.
This could be inline under schema or could be by ref like in the example $ref: '#/components/schemas/User'
components:
schemas:
User:
title: User
type: object
description: ''
examples:
- id: 142
firstName: Alice
lastName: Smith
email: [email protected]
dateOfBirth: '1997-10-31'
emailVerified: true
signUpDate: '2019-08-24'
- id: 143
firstName: John
lastName: Doe
email: [email protected]
dateOfBirth: '1997-10-31'
emailVerified: true
signUpDate: '2019-08-24'
properties:
id:
type: integer
description: Unique identifier for the given user.
firstName:
type: string
lastName:
type: string
email:
type: string
format: email
dateOfBirth:
type: string
format: date
example: '1997-10-31'
emailVerified:
type: boolean
description: Set to true if the user's email has been verified.
createDate:
type: string
format: date
description: The date that the user was created.
required:
- id
- firstName
- lastName
- email
- emailVerified
If you need help let me know!
from camouflage.
@jeroenherczeg: This was closed incorrectly, however the task is completed. Refer to the documentation.
Feel free to reopen the issue, if additional changes are required.
from camouflage.
Related Issues (20)
- Handlebar helpers should have access to gRPC metadata HOT 1
- grpc mocking does not support proxying
- Question: How to get value from application/x-www-form-urlencoded body? HOT 5
- Request matcher not working on grpc HOT 6
- Schema validation HOT 4
- type error on new validation HOT 4
- TypeError in v0.10.1 when validation is disabled
- Provide a docker image that supports arm64v8 architecture HOT 1
- can we access the metric for GRPC requests
- Header Location ist not set propertly HOT 3
- text/plain treated as json HOT 3
- Custom handlebars are not working HOT 2
- [Question] Would it be possible to allow async IIFEs for pg helper? HOT 2
- Receiving html <br> tags instead of \n in response HOT 4
- File helper: Error: Can't set headers after they are sent. HOT 1
- `ReferenceError: require is not defined` while loading external middleware HOT 4
- `express.text()` middleware overrides other content types HOT 4
- Add gRPC '-bin' metadata support
- Publish images for latest releases to Docker Hub
- Example of #code helper for grpc mocks HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from camouflage.