예제 #1
0
파일: object.go 프로젝트: Jumpscale/go-raml
// generateObjectFromBody generate a Nim object from an RAML Body
func generateObjectFromBody(methodName string, body *raml.Bodies, isReq bool, dir string) (string, error) {
	if !commons.HasJSONBody(body) {
		return "", nil
	}
	obj, err := newObjectFromBody(methodName, body, isReq)
	if err != nil {
		return "", err
	}
	return obj.Name, obj.generate(dir)
}
예제 #2
0
파일: body.go 프로젝트: Jumpscale/go-raml
// generate a struct from an RAML request/response body
func generateStructFromBody(structNamePrefix, dir, packageName string, body *raml.Bodies, isGenerateRequest bool) error {
	if !commons.HasJSONBody(body) {
		return nil
	}

	// construct struct from body
	structDef := newStructDefFromBody(body, structNamePrefix, packageName, isGenerateRequest)

	// generate
	return structDef.generate(dir)
}
예제 #3
0
파일: class.go 프로젝트: Jumpscale/go-raml
// generate classes from a method
//
// TODO:
// we currently camel case instead of snake case because of mistake in previous code
// and we might need to maintain backward compatibility. Fix this!
func generateClassesFromMethod(m serverMethod, dir string) error {
	// request body
	if commons.HasJSONBody(&m.Bodies) {
		name := inflect.UpperCamelCase(m.MethodName + "ReqBody")
		class := newClass(name, "", m.Bodies.ApplicationJSON.Properties)
		if err := class.generate(dir); err != nil {
			return err
		}
	}

	// response body
	for _, r := range m.Responses {
		if !commons.HasJSONBody(&r.Bodies) {
			continue
		}
		name := inflect.UpperCamelCase(m.MethodName + "RespBody")
		class := newClass(name, "", r.Bodies.ApplicationJSON.Properties)
		if err := class.generate(dir); err != nil {
			return err
		}
	}
	return nil
}