cue icon indicating copy to clipboard operation
cue copied to clipboard

encoding/openapi: ynable to generate OpenAPI Schema due to non-concrete value bounding

Open lujiajing1126 opened this issue 10 months ago • 6 comments

What version of CUE are you using (cue version)?

$ cue version
v0.12.0 (Go Mod import)

Does this issue reproduce with the latest stable release?


	#Resource: {
		requests: {
			cpu: number
			memory: number
		}
		limits: {
			cpu: number & >= requests.cpu
			memory: number & >= requests.memory
		}
	}

What did you do?

Using Go API to generate OpenAPI V3 Schema generates the following error,

#parameter.deployment.resource.limits.cpu: non-concrete value requests.cpu for bound >=

Image

Follow the method described in the doc, https://cuelang.org/docs/concept/how-cue-works-with-openapi/

What did you expect to see?

v0.5.x does not report this error

What did you see instead?

I understand that OpenAPI does not support this feature, so we may provide an option to ignore such unsupported features?

lujiajing1126 avatar Feb 11 '25 03:02 lujiajing1126

Image

This issue may be caused by https://github.com/cue-lang/cue/commit/e1ceed434f211be0c6bdd3d8fea767765b1b0b92

lujiajing1126 avatar Feb 11 '25 04:02 lujiajing1126

@lujiajing1126 - please can you include some example CUE that reproduces the problem?

myitcv avatar Feb 18 '25 13:02 myitcv

@lujiajing1126 - please can you include some example CUE that reproduces the problem?

Image

#Resource: {
	requests: {
		cpu:    number
		memory: number
	}
	limits: {
		cpu: >=requests.cpu & {
			number
		}
		memory: >=requests.memory & {
			number
		}
	}
}

An example pasted above

lujiajing1126 avatar Feb 25 '25 07:02 lujiajing1126

Thanks @lujiajing1126 - please can you confirm what OpenAPI you would expect to be output here?

cc @rogpeppe

myitcv avatar Feb 25 '25 10:02 myitcv

Friendly nudge @lujiajing1126 - what would you expect the OpenAPI output here to be?

mvdan avatar Apr 14 '25 09:04 mvdan

Friendly nudge @lujiajing1126 - what would you expect the OpenAPI output here to be?

Sorry for the late reply.

openapi: 3.0.0
info:
  title: Generated by cue.
  version: no version
paths: {}
components:
  schemas:
    Resource:
      type: object
      required:
        - requests
        - limits
      properties:
        requests:
          type: object
          required:
            - cpu
            - memory
          properties:
            cpu:
              type: number
            memory:
              type: number
        limits:
          type: object
          required:
            - cpu
            - memory
          properties:
            cpu:
              type: number
            memory:
              type: number

This is what I expect, generated by cue v0.5.0. I understand for OpenAPI V3 Schema, it is not possible to compare two fields.

lujiajing1126 avatar Apr 15 '25 01:04 lujiajing1126