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

Render() function panics due to ignored error #264

Closed
SAPRD2 opened this issue Mar 7, 2024 · 1 comment
Closed

Render() function panics due to ignored error #264

SAPRD2 opened this issue Mar 7, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@SAPRD2
Copy link

SAPRD2 commented Mar 7, 2024

libopenapi version: 0.15.14

The RenderAndReload() function panics with the given spec due to the error being ignored at YAMLNodeToJSON function.

The complete flow of function is: RenderAndReload -> Render -> RenderJSON -> YAMLNodeToJSON -> handleYAMLNode.

The error coming from handleYAMLNode is yaml: cannot decode !!float `-999.99` as a !!int. Due to the same, the variable newbytes is empty which leads to an error further in the code.

Below is a simple go program which demonstrates the same

package main

import (
	"fmt"
	"github.com/pb33f/libopenapi"
)

const openAPISpec = `{"openapi":"3.0.0","info":{"title":"dummy","version":"1.0.0"},"paths":{"/dummy":{"post":{"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"value":{"type":"number","format":"decimal","multipleOf":0.01,"minimum":-999.99}}}}}},"responses":{"200":{"description":"OK"}}}}}}`

func main() {

	document, _ := libopenapi.NewDocument([]byte(openAPISpec))

	_, _ = document.BuildV3Model()

	_, _, _, _ = document.RenderAndReload() // code panics here
}

Spec:

{
  "openapi": "3.0.0",
  "info": {
    "title": "dummy",
    "version": "1.0.0"
  },
  "paths": {
    "/dummy": {
      "post": {
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "value": {
                    "type": "number",
                    "format": "decimal",
                    "multipleOf": 1.0e-2,
                    "minimum": -999.99
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    }
  }
}
@daveshanley daveshanley added the bug Something isn't working label Mar 7, 2024
daveshanley added a commit that referenced this issue Apr 18, 2024
Error was not being returned when rendering JSON
@daveshanley daveshanley mentioned this issue Apr 18, 2024
daveshanley added a commit that referenced this issue Apr 19, 2024
Error was not being returned when rendering JSON
@daveshanley
Copy link
Member

This was resolved in v0.16.0 The error is handled and a test was added to validate

https://github.com/pb33f/libopenapi/blob/main/document_test.go#L1335

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants