Comments (2)
@srilman thanks for the issue! I believe this was done on purpose because Go can't use reflection to access private fields from other packages, so it would be inconsistent to allow access from within your package but disallow it from imported packages. I can dig a bit deeper just to confirm this is the case with embedded private fields.
from huma.
And from my understanding, to change this behavior, we just need to change function getFields
in file huma/schema.go
:
func getFields(typ reflect.Type, visited map[reflect.Type]struct{}) []fieldInfo {
fields := make([]fieldInfo, 0, typ.NumField())
var embedded []reflect.StructField
if _, ok := visited[typ]; ok {
return fields
}
visited[typ] = struct{}{}
for i := 0; i < typ.NumField(); i++ {
f := typ.Field(i)
if !f.IsExported() {
continue
}
if f.Anonymous {
embedded = append(embedded, f)
continue
}
fields = append(fields, fieldInfo{typ, f})
}
for _, f := range embedded {
newTyp := f.Type
for newTyp.Kind() == reflect.Ptr {
newTyp = newTyp.Elem()
}
if newTyp.Kind() == reflect.Struct {
fields = append(fields, getFields(newTyp, visited)...)
}
}
return fields
}
All to change is move this snippet:
if !f.IsExported() {
continue
}
underneath the if statement if f.Anonymous {
from huma.
Related Issues (20)
- Race condition detected in Huma v2.22.0 HOT 2
- The 'pattern' struct tag does not work in some cases. HOT 2
- Missed schema `pattern` on the OAS generation. HOT 1
- Faced unexpected panicking on types with Resolve implementation. HOT 3
- [Question] Implementation of `ContentTypeFilter` doesn't affect OAS generation. HOT 1
- Primitive-based types are not reused in the generated OAS. HOT 3
- [Question]: Is it possible to change default HTTP Status Code on Validation Error? HOT 2
- Request RawBody in middleware HOT 2
- Setting up only `description` in `requestBody`
- No access to "context.Context" from "huma.NewError"
- time.RFC3339
- Custom properties with struct tags?
- Validation for input tags like uri, hostname not working
- Dependency Error while installing huma HOT 1
- how to integrate websockets, should the need arise?
- Schema change for arrays has broken API compatibility HOT 1
- Feature request - Ability to write errors to huma.Context during a StreamResponse
- Case Sensitivity For JSON tags
- unsupported param type url.URL
- Any way to create a CLI out of the web server?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from huma.