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 1 commit 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.606%. remained the same
when pulling 89bbb38 on JAORMX:generate-ds
into 4f22b50 on mindersec:main.

…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]>
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