compeller icon indicating copy to clipboard operation
compeller copied to clipboard

feat: Add CLI for compeller `add` to support path, method based construction of the schema

Open simonireilly opened this issue 3 years ago • 0 comments

This PR introduces:

yarn compeller add createUser --path /v1/user --method post

A command for injection of a new path with an associated schema.

The injection will ultimately lead to requiring expansion, to support the full API, and this will be problematic, as we are currently only allowing path and method.

The suggestion would be to enable for a fast MVP creation of common scenarios.

Resource

Assumes something like a rails resource for a restful model

yarn compeller resource v1/users

Which adds opinionated JSON return types for the path:

  • get /v1/users with 200 code, 403 code
  • get /v1/users/{id} with 200 code, 404 code, 403 code
  • post /v1/users with 201 code, 422 code, 403 code
  • delete /v1/users/{id} with 204 code, 403 code, 404 code

And would create a schema for NewUser, User, and potential Users as a list, but this would be coupled to User model.

Todo

  • [ ] Support injection fully, for existing files
  • [ ] Develop a testing methodology for compeller behaviors to enable integration testing of injection
    • [ ] For example, repeated running should be idempotent.
    • [ ] For example injection into paths with an existing method should be supported.

Justification

Injection can provide rapid development of the JSON schema, whilst also enforcing a convention.

If the convention is sensible, and idiomatic for example, just by building a folder structure, that mirrors the OpenAPI specification, then users will lean into it.

Is this open for extension?

Yes, injection/generation allows full flexibility, think of rails routes, or active model

simonireilly avatar Feb 26 '22 16:02 simonireilly