Git Product home page Git Product logo

Comments (3)

matoszz avatar matoszz commented on August 17, 2024 1

I believe i'm impacted by a similar issue when trying to use field.JSON and specifying []strings{} in the field type. I've tried many permutations of annotations or other config but the failure message (super unhelpful) is:

running ent codegen: execute template "ogent/responses": template: response.tmpl:17:6: executing "ogent/responses" at <setFieldExpr $f $n "ret" "e">: error calling setFieldExpr: unexpected type: ""

I'm additionally confused why I'm unable to use ogen.String().AsArray() even though it's in the declaration for the field.JSON type: https://github.com/ent/contrib/blob/master/entoas/generator_test.go#L65

from ogent.

jamesw201 avatar jamesw201 commented on August 17, 2024

Agree with @matoszz, the only annotation that I've found will get field.JSON to work with entoas is something like:

type Model struct {
    ent.Schema
}

func (Model) Fields() []ent.Field {
	return []ent.Field{
    field.Int("id"),
    field.String("name"),
    field.JSON("location", []byte{}).
        Annotations(entoas.Schema(&ogen.Schema{
            Type:        "object",
            Description: "Location",
            Properties: []ogen.Property{
                {Name: "latitude", Schema: ogen.Double()},
                {Name: "longitude", Schema: ogen.Double()},
            },
        })),
    }
}

as described here: ent/ent#3573 (comment)

Whilst that will generate an openapi.json file, it then causes issues in ogent with:

ent/ogent/ogent.go:35:16: cannot use req.Location (variable of type CreateModelReqLocation) as []uint8 value in argument to b.SetLocation
ent/ogent/ogent.go:103:17: cannot use v (variable of type UpdateModelReqLocation) as []uint8 value in argument to b.SetLocation
ent/ogent/responses.go:14:17: cannot use e.Location (variable of type []uint8) as ModelCreateLocation value in assignment
ent/ogent/responses.go:43:17: cannot use e.Location (variable of type []uint8) as ModelListLocation value in assignment
ent/ogent/responses.go:72:17: cannot use e.Location (variable of type []uint8) as ModelReadLocation value in assignment
ent/ogent/responses.go:101:17: cannot use e.Location (variable of type []uint8) as ModelUpdateLocation value in assignment

Is there a way to have JSON.field describe a json object that entoas and ogent are happy with?

from ogent.

Kirby980 avatar Kirby980 commented on August 17, 2024

running ent codegen: execute template "ogent/responses": template: response.tmpl:17:6: executing "ogent/responses" at <setFieldExpr $f $n "ret" "e">: error calling setFieldExpr: unexpected type: "" Is this the reason to use field.JSON?

from ogent.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.