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

Yaml support for API definition #1049

Merged
merged 10 commits into from
Nov 5, 2024
Merged

Yaml support for API definition #1049

merged 10 commits into from
Nov 5, 2024

Conversation

afsalthaj
Copy link
Contributor

@afsalthaj afsalthaj commented Nov 2, 2024

TODO

  • Make sure multiline Rib works in yaml (just to validate prioritizing this work)
  • REST-API support for importing open-api-format-api-definition for both yaml and json using content-type negotiation. yaml content-type in header will support yaml import.
  • golem-CLI support for importing open-api-format-api-definition for both yaml and json.
  • REST-API Native API definition format, supporting both yaml and json. Here, make sure to support output yaml and json formats. Probably output can be a concern of just clients instead of lots of changes required in client generation side to support Accept headers (similar to content type header)
  • golem-cli support for Native API definition format in both yaml and json format. Specify --def-format yaml if importing yaml spec through golem-cli. json is by default to keep backward compatibility.
  • Make sure multiple content type is specified in generated golem-service.yaml spec, and make sure client-generator code works with this. I had to fix a lot there: See golemcloud/golem-openapi-client-generator@master...support_yaml
  • FYI: CLI tests succeed only if we strongly distinguish yaml and json parsing, instead of trying to magically parse anything that user passes without any hint of what's the format of file (hints being content-type for REST API, and --def-format for CLI), and also error reporting becomes clear.

OpenAPI in yaml format with multi-line Rib that works

openapi: "3.0.0"
info:
  title: "Sample API"
  version: "1.0.3"
x-golem-api-definition-id: "myapi"
x-golem-api-definition-version: "0.1.1"
paths:
  "/{user-id}/get-cart-contents":
    x-golem-worker-bridge:
      worker-name: "\"foo\""
      component-id: "aae6dd36-8caa-4271-8ef3-cf1f88ef9c97"
      component-version: 0
      response: |
        let style = "font-family: Arial, sans-serif; display: flex; align-items: center; 
                     justify-content: center; height: 100vh; background: linear-gradient(135deg, 
                     #1e3c72, #2a5298); color: #ffffff; text-align: center; padding: 20px;";
        let user: u64 = request.path.user-id;
        {
          Content-Type: "text/html",
          status: 200u64,
          body: "<!DOCTYPE html><html><head></head><body style='${style}'>
                 <div><h1>Welcome to Golem Cloud!</h1>
                 <p style='font-size: 1.5em;'>Hello, User ID: ${user}</p>
                 <p style='color: #dcdcdc;'>Explore your cart contents and more on this personalized page.</p>
                 </div></body></html>"
        }
    get:
      summary: "Get Cart Contents"
      description: "Get the contents of a user's cart"
      parameters:
        - name: "user-id"
          in: "path"
          required: true
          schema:
            type: "string"
      responses:
        "200":
          description: "OK"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/CartItem"
        "404":
          description: "Contents not found"
components:
  schemas:
    CartItem:
      type: "object"
      properties:
        id:
          type: "string"
        name:
          type: "string"
        price:
          type: "number"

@afsalthaj afsalthaj changed the title Yaml support in CLI Yaml support for API definition Nov 2, 2024
@afsalthaj
Copy link
Contributor Author

Part of ##1035

@afsalthaj afsalthaj merged commit b861a50 into main Nov 5, 2024
18 checks passed
@afsalthaj afsalthaj deleted the yaml_support branch November 5, 2024 11:48
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.

2 participants