Giter Site home page Giter Site logo

Comments (4)

shubhendumadhukar avatar shubhendumadhukar commented on May 22, 2024 1

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.

shubhendumadhukar avatar shubhendumadhukar commented on May 22, 2024

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.

jeroenherczeg avatar jeroenherczeg commented on May 22, 2024

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.

shubhendumadhukar avatar shubhendumadhukar commented on May 22, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.