Coder Social home page Coder Social logo

oas-cli's Issues

[BUG] ERR_MODULE_NOT_FOUND when generating server with Dockerfile

Describe the bug

When initializing a new server using the CLI tool, if the option to generate the Dockerfile is set the server will throw an error when executing npm start:

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'server.js' imported from E:\Alex\Desktop\adsdsd\generated-server\index.js
    at new NodeError (node:internal/errors:371:5)
    at packageResolve (node:internal/modules/esm/resolve:884:9)
    at moduleResolve (node:internal/modules/esm/resolve:929:18)
    at defaultResolve (node:internal/modules/esm/resolve:1044:11)
    at ESMLoader.resolve (node:internal/modules/esm/loader:422:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:222:40)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)
    at link (node:internal/modules/esm/module_job:75:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}

To Reproduce

Steps to reproduce the behavior:

  1. Create an OpenAPI document
  2. Run npx @oas-tools/cli init and select server
  3. Select the option to generate a Dockerfile
  4. Once generated, run npm start inside the new server directory.

Expected behavior

The server should start normally, installing all dependencies previously.

[BUG] Array properties staring from an entity resource

Describe the bug
When we declare arrays inside the entities and execute the cli for the creation of the oas-doc from a json. These are taken as their type in javascript typeof [1,2,3,4] // Returns "object".
To Reproduce
Steps to reproduce the behavior:

  1. Create a json file like
[
    {
        "id": 1,
        "name": "User",
        "email": "[email protected]",
        "pets": [ 
           {
               "id": 1,
               "petName": "Garfield",
               "type": "Cat"
           }
        ]
    }
]
  1. Exec npx @oas-tools/cli init to create OpenAPI File

[BUG] Default oas file generated has a different name than the default name expected in oas-tools/core

When generating a server with the CLI, the default configuration included in index.js does not specify the OAS file the server was generated from.

The validation that oas-tools perform expects that, if no oas file is specificied in the configuration object passed to the initialize function, the default OAS file will be at api/oas-file.yaml. However, the CLI generates it as api/oas-doc.yaml, causing an initialization error as a consequence if no explicit config is provided.

It would be better to sync somehow the two default names both in CLI and in core modules.

`204` should be an integer in the generated OpenAPI document

When generating an OpenAPI document from an entity resource file, the 204 status is the only one that is generated as a string instead of as an integer.

Other (non-204) response statuses look like the following:

responses:
    200:
      description: Item found by id

For 204s, it will instead look like this:

responses:
    "204":
      description: Item deleted

To Reproduce

Steps to reproduce the behavior:

  1. Use an entity resource file to create an OpenAPI document with the CLI
  2. In the interactive prompt, for any given entity, select the HTTP methods PUT and/or DELETE
  3. Check the generated OpenAPI document to see that the 204s are noted as strings

Expected behavior

Instead of "204", the status should simply be 204 (no quotation marks).

[BUG] Awkward phrasing in prompt message

Describe the bug

Awkward phrasing in serverPrompt and filePrompt

To Reproduce

Steps to reproduce the behavior:

  1. Go to 'serverPrompt'
  2. Scroll down to 'line 5'
  3. See message

Steps to reproduce the behavior:

  1. Go to 'filePrompt'
  2. Scroll down to 'line 93'
  3. See message

Expected behavior

A clear and concise message explaining what will happen.

Additional context

None.

Pluralize "get all" (i.e. find many) endpoints in the generated OpenAPI document

Context

Using the CLI to generate an OpenAPI document from an entity resource file for a given resource like User.

Issue

The CLI generates the following lines containing an operationId that should probably be plural:

  /api/v1/users:
    get:
      description: Returns all users
      operationId: getUser
      responses:
        200:
          description: User list
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/user'

Note how the endpoint and description are plural as expected, and the success response is an array, yet the operationId is singular.

In turn, when generating a server based on this OpenAPI document, we'll end up with a controller that looks like this:

export function getUser(req, res) {
    service.getUser(req, res);
}

The function name would seem to imply that we'll only be getting one user back. However, the return value is going to be an array with any number of users.

Expected outcome

Instead of getUser, the operation should be named getUsers.

The code

I haven't done a thorough check, but this appears to be where it's happening:

description: Returns all {{lookup ../resources @index}}
operationId: get{{lookup ../Resource @index}}

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.