Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQLalchemy support #2

Open
SamuelMarks opened this issue May 15, 2015 · 6 comments
Open

SQLalchemy support #2

SamuelMarks opened this issue May 15, 2015 · 6 comments

Comments

@SamuelMarks
Copy link

I've been working on an SQLalchemy branch.

Do you want me to form a pull-request out of it?

@rejown
Copy link
Member

rejown commented May 15, 2015

Nice idea, but will you implement this as an optional feature?

I tried to explain it, and then discuss.

The generated code can be divided into two categories: overwritable and non-overwritable.

The code overwritable is totally defined by swagger docs, and the code non-overwritable is generated on first time, then maintained by the user.

The overwritable codes include:

  • routes, defined by path and method in swagger.
  • schemas, defined by parameters and schemas in swagger.
  • validators, use schemas validate the request.
  • filters, use schemas filter the response.

swagger-py-codegen' s purpose is to make those overwritable codes can be simply updated when the swagger doc is changed.

The other codes, for example, views, views content is not totally decided by swagger-py-codegen, so it's content will not be overwritten by default.

SQLAlchemy's model like views, the user will handle it contents, so it should be non-overwritable by default.

Another purpose of the project is: generates the necessary code for make a running application as the swagger doc defined.

The SQLAlchemy model is not a necessary condition for the working app, but the model code may be very useful for some scene.

So if this is an optional feature, we will be very pleased to accept your PR.

p.s. I intend to implement a custom template feature so that it can adapt to more special scene.

Thanks.

@SamuelMarks
Copy link
Author

Yeah, I've been thinking about this, essentially I'll need a much more general solution, that generates:

  • Models
  • Persistence (optional)
  • Tests (including mocks)
  • Routes

… and can go in the reverse (back to Swagger from changes in models and/or routes)

PS: My Blueprints are quite different now, as I'm using bottle with separate a different "api" in each directory, e.g.: user_api, profile_api, auth_api, friends_api.

@daisymark
Copy link

wonderful!~~

@advance512
Copy link

So.. was this merged in?

@rejown
Copy link
Member

rejown commented Dec 26, 2016

Not yet.

I think there will be many challenges in translate JSON schema to SQLAlchemy model, there is a project alchemyjsonschema which can convert SQLAlchemy model to JSON schema as a reference.

SQLAlchemy model needs to know which property is the primary key, and which is the index, in some cases, we don't want to expose some properties in a model, or expose some model. Those problems may resolve with the x- property in Swagger for extending same database concepts.

jizhouli pushed a commit that referenced this issue Apr 13, 2017
@leslie-wang
Copy link

leslie-wang commented Jul 25, 2017

First of all, thanks for the great project. It is very useful.

Most likely people using this generator is at the early stage of the project. At that time, all codes are overridable. :-)

Seems like all files under /api are non-overridable. If that is the case, why not making another folder "/db", put db related operation there. Some argument can add to let user select skip or upgrade or override.

Just 2 cents.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants