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

RenderAndReload() errors out if spec has negative floating point numbers for minimum or maximum #376

Closed
pratik-sharma-1 opened this issue Feb 14, 2025 · 1 comment · Fixed by #377

Comments

@pratik-sharma-1
Copy link
Contributor

Issue details

RenderAndReload() errors out if spec has negative floating point numbers for minimum or maximum

Steps to reproduce

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": 0.01,
                                        "minimum": -999.99
                                    }
                                }
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    }
}

Sample go program

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, err := libopenapi.NewDocument([]byte(openAPISpec))
	if err != nil {
		panic(err)
	}

	_, errList := document.BuildV3Model()

	if len(errList) > 0 {
		fmt.Println(errList)
		panic("error encountered while building the model")
	}

	_, _, _, errList = document.RenderAndReload()
	if len(errList) > 0 {
		fmt.Println(errList)
		panic("error encountered while rendering the model")
	}
}

Current behaviour

RenderAndReload() errors with [yaml: cannot decode !!float -999.99 as a !!int]

Expected behaviour

Since minimum and maximum are defined as numbers , negative values should be valid

Possible cause:

  1. Explicit check of value > 0 : https://github.com/pb33f/libopenapi/blob/main/datamodel/high/node_builder.go#L504-L511
  2. Similar check is also present at : https://github.com/pb33f/libopenapi/blob/main/datamodel/high/node_builder.go#L495-L498

Reference

https://datatracker.ietf.org/doc/html/draft-wright-json-schema-validation-00#section-5.4
https://datatracker.ietf.org/doc/html/rfc7159#section-6

@pratik-sharma-1
Copy link
Contributor Author

I have also tried to fix the issue PR: #377

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 a pull request may close this issue.

1 participant