Code Monkey home page Code Monkey logo

Comments (3)

emicklei avatar emicklei commented on August 25, 2024

Just to collect the specs:

// Field is ignored by json package.
Field int `json:"-"`

This one is indeed missing and can be supported easily.

// the field is omitted from the object if its value is empty,
// as defined above.
Field int `json:"myName,omitempty"`

How should this be reflected in Swagger? It should not be in the "required" list (at the moment this is not filled).

What do you mean by "Fields tagged with strings" ?

from go-restful.

viblo avatar viblo commented on August 25, 2024

Right, omitempty is a bit tricky now that you mention it.. My use case is a common Response object that is returned in all my GET methods. The response object has a couple of common fields and then specific ones that are filled depending on method. Here is an example of that object:

type Response struct {
  Code int `json:"code"`
  Users *[]User `json:"users,omitempty"`
  Items *[]Item `json:"items,omitempty"`
}

In this case I might have the resources /users and /items, and depending on resource either Users or Items will contain anything.

One idea would be to only emit the documentation listing for the field if the "template" object sent in has a instance of it (this was what I tried first myself before I realized that it didnt work at all). So if the code is like this ws.Writes(Response{Users:&[]User{}}) the user field would be included but not the items field.

However, Im not sure how to handle the case where a object is used twice (both Reads and Writes), and the template is different. (In my case this wont happen the way my code is structured)

The strings tag means that the field will be serialized as a string even if its a int or float: http://golang.org/pkg/encoding/json/#Marshal (I dont need this feature myself, but thought it would be good to handle it at the same time as the other json tags are dealt with.

from go-restful.

emicklei avatar emicklei commented on August 25, 2024

I created a new Issue #86 for getting support for the remaining part.

from go-restful.

Related Issues (20)

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.