Skip to content

What does -p option do? #305

@jmjf

Description

@jmjf

Problem

Working to fix #294, I realized I cannot figure out what the -p, --properties option is supposed to do. That's probably a "me" problem. Can someone please explain so we can understand how to fix the option for oas2tson or remove it.

If the team can provide some feedback on intent and preferred direction in light of discussion on #230, I don't mind trying to put together code and a PR.

Background

In oas2json and oas2tson, the option is defined as:

  .option(
    '-p, --properties <string>',
    'Comma-separated list of properties to convert from the OpenAPI file'
  )

The option is not available for oas2ts or json2ts.

The examples use -p paths, like openapi-transformer-toolkit oas2json -i ./openapi.yml -o ./schemas -p paths.

For oas2json, adding -p paths outputs a paths directory with JSON Schema files for the paths. Based on the description, I'd expect -p User,Tag to output only User and Tag. But adding a comma separated list fails with the message, "Failed to convert non-object attribute, skipping." Based on the code, components.schemas is always added to the list of properties.

For oas2tson, as reverted, -p paths fails. According to comments in #224, pets/findByStatus becomes const pets-findByStatus because - is not valid character in a JavaScript identifier. The - is not a problem for oas2json because oas2json writes JSON Schema, not variables.

Note PR seems to be trying to implement path generation, which later spawned #230 mentioned above. There, is seems like the team isn't convinced the tool should support TSON path generation. If it shouldn't, should it support JSON path generation either?

The name pets-findByStatus is really the filename for the output file. For example, oas2json writes file names like pets-findByStatus.json and pets-{petId}.json. The name is generated by filenamify(name, { replacement: '-' }) in both oas2tson and oas2json.

Questions

  • What is --properties supposed to do? What benefit does it bring?

    • Is it supposed to include major branches of the OpenAPI spec other than components.schemas?
    • Is the idea we could have headers or other things too?
    • Is this a property or is it a directory in an OpenAPI spec that uses multiple files and directories?
    • Are there branches of the OpenAPI spec that should not be allowed?
  • Should oas2tson support -p paths? (How symmetric should oas2json and oas2tson be?)

  • If so how should path consts be named?

    • pets-findByStatus isn't valid JavaScript.
    • URLs are case sensitive so pets/findByStatus and pets/FindByStatus are different URLs, unless you configure your server to be case insensitive.
    • Maybe pets_findByStatus and pets_FindByStatus? Those are valid, but not idiomatic, JS names. Given URL case sensitivity not idiomatic may be necessary.
  • Or if not, then should we remove the -p option from oas2tson?

Looking at oas2tson vs. oas2json, It feels wrong that they're so different. Maybe too simplistic, but TSON is just JSON with no quotes around the member names and a const <name> = in front of it and as const on the end. Somewhere in Nodeland there must be a JavaScript code generator that can take an object and generate output suitable for including in a file. json2ts is basically what we need, but with the values instead of the types. Then something like oas2json -> JSON.parse() -> object2json + as const should work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions