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

mindev: Add utility to generate a data source definition from a Swagger doc #5283

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

JAORMX
Copy link
Contributor

@JAORMX JAORMX commented Jan 10, 2025

Summary

This adds the following command: mindev datasource generate ...

The aforementioned command will read a swagger doc (OpenAPI v2) and will
generate the appropriate data source definition out of it.

I went for v2 since there was an easy-to-use implementation ready.
Adding v3 support is left as a TODO item.

Here's a demo of how usage would look like:

$ cat sample.yaml
swagger: "2.0"

info:
  title: Sample API
  description: Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML.
  version: 0.1.9

basePath: http://api.example.com/v1

paths:
  /users:
    get:
      summary: Returns a list of users.
      description: Optional extended description in CommonMark or HTML.
      responses:
        "200": # status code
          description: A JSON array of user names
          content:
            application/json:
              schema:
                type: array
                items:
                  type: string

$ go run cmd/dev/main.go datasource generate sample.yaml
version: v1
type: data-source
context: {}
name: Sample-API
rest:
  def:
    get_users:
      endpoint: http://api.example.com/v1/users
      method: GET
      parse: json
      inputSchema: {}

Change Type

Mark the type of change your PR introduces:

  • Bug fix (resolves an issue without affecting existing features)
  • Feature (adds new functionality without breaking changes)
  • Breaking change (may impact existing functionalities or require documentation updates)
  • Documentation (updates or additions to documentation)
  • Refactoring or test improvements (no bug fixes or new functionality)

Testing

Outline how the changes were tested, including steps to reproduce and any relevant configurations.
Attach screenshots if helpful.

Review Checklist:

  • Reviewed my own code for quality and clarity.
  • Added comments to complex or tricky code sections.
  • Updated any affected documentation.
  • Included tests that validate the fix or feature.
  • Checked that related changes are merged.

@JAORMX JAORMX requested a review from a team as a code owner January 10, 2025 12:43
@coveralls
Copy link

coveralls commented Jan 10, 2025

Coverage Status

coverage: 56.609% (+0.003%) from 56.606%
when pulling 8d83735 on JAORMX:generate-ds
into 2caea05 on mindersec:main.

@JAORMX JAORMX force-pushed the generate-ds branch 2 times, most recently from 89bbb38 to 3bc684b Compare January 13, 2025 08:04
Copy link
Member

@rdimitrov rdimitrov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add 1 or more tests so we can ensure we don't accidentally break the generation part. Otherwise it looks good 👍

cmd/dev/app/datasource/datasource.go Outdated Show resolved Hide resolved
cmd/dev/app/datasource/generate.go Outdated Show resolved Hide resolved
@JAORMX
Copy link
Contributor Author

JAORMX commented Jan 13, 2025

Can we add 1 or more tests so we can ensure we don't accidentally break the generation part. Otherwise it looks good 👍

will do... on Wednesday 😄

JAORMX and others added 3 commits January 13, 2025 12:03
…er doc

This adds the following command: `mindev datasource generate ...`

The aforementioned command will read a swagger doc (OpenAPI v2) and will
generate the appropriate data source definition out of it.

I went for v2 since there was an easy-to-use implementation ready.
Adding v3 support is left as a TODO item.

Here's a demo of how usage would look like:

```
$ cat sample.yaml
swagger: "2.0"

info:
  title: Sample API
  description: Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML.
  version: 0.1.9

basePath: http://api.example.com/v1

paths:
  /users:
    get:
      summary: Returns a list of users.
      description: Optional extended description in CommonMark or HTML.
      responses:
        "200": # status code
          description: A JSON array of user names
          content:
            application/json:
              schema:
                type: array
                items:
                  type: string

$ go run cmd/dev/main.go datasource generate sample.yaml
version: v1
type: data-source
context: {}
name: Sample-API
rest:
  def:
    get_users:
      endpoint: http://api.example.com/v1/users
      method: GET
      parse: json
      inputSchema: {}

```

Signed-off-by: Juan Antonio Osorio <[email protected]>
@rdimitrov
Copy link
Member

Can we add 1 or more tests so we can ensure we don't accidentally break the generation part. Otherwise it looks good 👍

will do... on Wednesday 😄

Oh, in that case I don't mind merging this one and doing it as a follow up 👍

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

Successfully merging this pull request may close these issues.

3 participants