예제 #1
0
// Execute runs this command
func (s *Server) Execute(args []string) error {
	opts := generator.GenOpts{
		Spec:          string(s.Spec),
		Target:        string(s.Target),
		APIPackage:    s.APIPackage,
		ModelPackage:  s.ModelPackage,
		ServerPackage: s.ServerPackage,
		ClientPackage: s.ClientPackage,
		Principal:     s.Principal,
	}

	if !s.SkipModels && (len(s.Models) > 0 || len(s.Operations) == 0) {
		if err := generator.GenerateDefinition(s.Models, true, true, opts); err != nil {
			return err
		}
	}

	if !s.SkipOperations && (len(s.Operations) > 0 || len(s.Models) == 0) {
		if err := generator.GenerateServerOperation(s.Operations, s.Tags, true, true, opts); err != nil {
			return err
		}
	}

	if !s.SkipSupport {
		if err := generator.GenerateSupport(s.Name, s.Models, s.Operations, opts); err != nil {
			return err
		}
	}

	return nil
}
예제 #2
0
// Execute runs this command
func (c *Client) Execute(args []string) error {
	opts := generator.GenOpts{
		Spec:          string(c.Spec),
		Target:        string(c.Target),
		APIPackage:    c.APIPackage,
		ModelPackage:  c.ModelPackage,
		ServerPackage: c.ServerPackage,
		ClientPackage: c.ClientPackage,
		Principal:     c.Principal,
	}

	if !c.SkipModels && (len(c.Models) > 0 || len(c.Operations) == 0) {
		if err := generator.GenerateDefinition(c.Models, true, true, opts); err != nil {
			return err
		}
	}

	if !c.SkipOperations && (len(c.Operations) > 0 || len(c.Models) == 0) {
		if err := generator.GenerateClient(c.Name, c.Models, c.Operations, opts); err != nil {
			return err
		}
	}

	return nil
}
예제 #3
0
// Execute generates a model file
func (m *Model) Execute(args []string) error {
	if m.DumpData && len(m.Name) > 1 {
		return errors.New("only 1 model at a time is supported for dumping data")
	}
	return generator.GenerateDefinition(
		m.Name,
		!m.NoStruct,
		!m.NoValidator,
		generator.GenOpts{
			Spec:          string(m.Spec),
			Target:        string(m.Target),
			APIPackage:    m.APIPackage,
			ModelPackage:  m.ModelPackage,
			ServerPackage: m.ServerPackage,
			ClientPackage: m.ClientPackage,
			DumpData:      m.DumpData,
		})
}